Posts Tagged ‘gz’

Gzip Compress Apache’s Output

Posted in Technical on March 9th, 2010 by iyoung – Be the first to comment

This has been described many times and in many ways by so many sites, but usually the descriptions are long and tedious. If you simply want to know how to get your website’s pages to be compressed if the browser supports it, or not if the browser doesn’t add the following lines to your Apache configuration file: -

[sourcecode language="bash"]
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
[/sourcecode]

Basically compress anything that can be compressed using the gzip algorithm ignore images because they are already compressed.

I put these directives within my Virtualhost but they could be just used in an .htaccess file I believe.

To test it is working, install the firefox web developers plugin, open your page, click the information drop down and select the option to view the page headers you should see something like: -

[sourcecode language="bash"]
Date: Tue, 09 Mar 2010 10:42:56 GMT
Server: Apache/2.2.x (SGI)
X-Powered-By: PHP/5.1.xx
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Last-Modified: Tue, 09 Mar 2010 10:42:57 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip —– This being the item of interest
Content-Length: 12115
Content-Type: text/html; charset=UTF-8
X-Cache: MISS from conway
Connection: keep-alive
200 OK

[/sourcecode]