Gzip compression through .htaccess not working Gzip compression through .htaccess not working php php

Gzip compression through .htaccess not working


I have not used mod_gzip but here is my .htaccess I use to gzip .js, .css and other files via mod_deflate:

#Gzip<ifmodule mod_deflate.c>AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x- javascript application/javascript</ifmodule>#End Gzip

In case you are not already aware of it, Firebug is very useful for checking if downloaded content is gzipped. Click on the "Net" tab in Firebug and then do shift-f5 to get Firefox to reload all the .js and .css files so they show in the Net panel. Click the "+" next to the .js or .css file and click the "Headers" tab. If the response is gzipped you will see "Content-Encoding gzip" in the Response Headers section. I image the IE, Safari, and Chrome equivalents offer the same ability.

There is one gotcha regarding gzipping .js and .css files on IE6 to watch out for. I think it is only applicable to IE6 SP1 users.


Here is a syntax to use with file extensions.

<IFModule mod_deflate.c>    <filesmatch "\.(js|css|html|jpg|png|php)$">        SetOutputFilter DEFLATE    </filesmatch></IFModule>


In my case, mod_gzip or mod_deflate was not working even after making it enabled and writing it in the htaccess file.

Then, I was end up using 'ob_gzhandler' in my php file, which helped me to compress my php and html files. This is not as good as mod_gzip or mod_deflate, but serve you temporarily in case if you can't get a luck on other.

The code which I used on my index.php file at top, before loading anything is,

<? ob_start("ob_gzhandler"); ?>