Speed Up and Save Traffic With Apache and Mod_deflate

One of our sites was loading pretty slow. This is mostly caused by a very heavy design. But i still wanted to speed things up a bit.

The first step was compressing all JavaScript files with the Yahoo YUI compressor. The next step was to activate mod_deflate and compress all text, XML, and media files (JavaScript, CSS).

When the mod_deflate module is loaded in apache this is a pretty easy thing to do. Just add the following lines to a .htaccess file in the root of the web site / application.

  • AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css
  • BrowserMatch ^Mozilla/4 gzip-only-text/html
  • BrowserMatch ^Mozilla/4.0[678] no-gzip
  • BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

The first line enables mod_deflate for the specified extensions. And the other three lines are there because of the way some older browsers handle gzipped data.

To test if the the content is transmitted over the line in gzipped format i used the Live HTTP Header Firefox extensions. This let’s you watch the Live HTTP headers as the fly by.

Check the HTTP/ 1.x 200 OK response from the webserver for the following line

Content-Encoding: gzip

And to test what happens if a browser doesn’t support gzipped data. You can set a configuration parameter in Firefox about:config.

gzip, deflate enabled:

network.http.accept-encoding = gzip,deflate

gzip, deflate disabled:

network.http.accept-encoding =

References : http://www.howtoforge.com/apache2_mod_deflate

comments powered by Disqus