Wednesday, June 04, 2008

Easy HTTP compression with mod_deflate

This is something that smack you in the face for not doing it any earlier. We have lots of internal documents served by our office Ubuntu server. Most of them are API docs which is in HTML. So it would make sense to turn on compression to save on the bandwidth. Well okay, it's mostly LAN so it's not that important. But small files will be faster to load up.

I am using Ubuntu Hardy so you may want to look up here on how to install mod_deflate manually.
Anyway to get mod_deflate to work with Apache2 this is what you have to do:

1. Sym link /etc/apache2/mod-available/deflate.conf and /etc/apache2/mod-available/deflate.load to /etc/apache2/mod-enable/

2. Edit deflate.conf. The default compression is only turn on for html, xml and plain text files. Add in "text/css text/javascript application/javascript application/x-javascript". This will enable compression for CSS and Javascripts files.

3. /etc/init.d/apache2 restart

If you have Web Developer Toolbar installed in your Firefox, go to Information -> View Document Size. You can see how much you have saved on the bandwith.

1 comment:

Jessi Hance said...

Thanks! You saved my sanity.