The Apache mod_deflate module compresses output on your server before sending it to the client. All modern browsers support this feature, and it is an easy way to stretch your bandwidth a little farther. Depending on the content on your site, you can see bandwidth savings of up to 25%
To enable, make sure that you have the Apache mod_deflate module installed (it is by default on most installations). Then simply put copy/paste these settings into your Apache config file
## Enable the module
LoadModule deflate_module modules/mod_deflate.so# Create the output filter
SetOutputFilter DEFLATE# Netscape 4.x has some problems…
BrowserMatch ^Mozilla/4 gzip-only-text/html# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4.0[678] no-gzip# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html## Don't compress for IE5.0
BrowserMatch "MSIE 5.0" no-gzip# Don't compress images, flash, PDFs, or JavaScript
# You might want to add more extensions to this list such as ogg|mp3|mov|avi
SetEnvIfNoCase Request_URI.(?:gif|jpe?g|png|swf|js|pdf)$ no-gzip dont-vary# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary## Sset up some stuff for mod_deflate stats
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratioLogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
## END mod_deflate configurationSometimes you want to deflate only text files. For that, comment out the SetEnvIfNoCase line and replace the "SetOutputFilter DEFLATE" line with the following:
AddOutputFilterByType DEFLATE text/css text/csv text/html text/plain application/xml application/xhtml+xml image/x-icon
Now, you can also add some extra logging to a virtual host to have the module save compression statistics about each request
CustomLog /var/logs/httpd/deflate.log deflate
Once you've made all of these changes to the Apache config, restart Apache to have them take effect.
Once you've been serving compressed files for a little while, you can use a script like the one at
http://prefetch.net/code/deflate-stats.pl to analyze the deflate_log and tell you how much bandwidth you have saved.
You can also use this handy link to test your setup, and if your browser is sending the right Accept-Encoding:
http://www.whatsmyip.org/mod_gzip_test/If your enabling mod_deflate because your site seems slow, and uses a lot of images or multimedia files, this link may be helpful:
http://developer.yahoo.com/performance/rules.html