How to run a site with gzip compression and why it matters
Since Google is now considering site speed for PageRank, it has made developers and SEO crowd thinking about it. Those familiar with Google Webmaster Tools probably know that site speed graph and related suggestions have been there for quite some time already.
First and probably the simplest thing is to turn on GNU zip compression, as also advised by Google Webmaster Tools (under Labs > Site performance). Doing so requires mod_deflate module on the Apache web server.
Turning on gzip
Given the above, enabling the compression couldn't be easier with only 1 line in the .htaccess of the site:
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
All it does is to turn on Gzip compression for each listed mime type. All browsers in use today can handle it.
For better readability a block of directives could be used instead:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
If there's uncertainty about whether or not Apache has mod_deflate, it's be smart to make it fail-safe by wrapping the directive(s) inside the IfModule section as Cezary pointed out in the comment below.
Case study
To illustrate the benefits, the directive was introduced on 7Kohvipoissi.ee. Here's the chart with page load speeds over 10 tests:
Data sheet (PDF, 45 KB)
Related resources:
- Online Gzip test to test the compression
- .htaccess (Wikipedia)
- GNU Gzip (Wikipedia)
- mod_deflate Apache Module
- Google Webmaster Tools