mod_deflate

by dev on Mar.08, 2009, under IT

One of the ways to optimize the loading speed of a website is to drastically reduce the size of all files sent to our clients and using gzip compression is the first solution that comes to my mind. Using mod_deflate in Apache2 is supported on most modern browsers, gives you statistics, filtering options based on MIME-type or even filename, caches the compressed files and is so easy to configure you’ll be drinking your coffee with a huge smile of satisfaction in less then 5 minutes.

First of all enable mod_deflate:
$ a2enmod deflate

Then edit /etc/apache2/mods-available/deflate.conf for a server wide configuration. For per-site configuration you can place these lines in your virtual hostsĀ  usually stored in apache2/sites-available.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
DeflateCompressionLevel 9
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
#If you want to enable logging uncomment the lines bellow
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#CustomLog /var/log/apache2/deflate_log deflate
</IfModule>

Restart apache
$ /etc/init.d/apache2 force-reload

If all goes well compression results can be seen in /var/log/apache2/deflate_log

Further reference:

  1. http://www.howtoforge.com/apache2_mod_deflate
  2. http://httpd.apache.org/docs/2.0/mod/mod_deflate.html
  3. http://railsgeek.com/2008/12/16/apache2-httpd-improving-performance-mod_deflate-gzip
  4. http://wiki.codemongers.com/NginxHttpGzipModule
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Previous Post
«
Next Post
»
:, ,

Tell us what you think