How can you reduce bandwidth consumed by your website by about 30% and considerably speed it up in about 5 minutes?
mod_deflate is a great apache2 module which provides on the fly compression of your website contents. If you have deployed your webserver in the past four years chances are your are already using it. However, mod_deflate by default will only compress your text/html, text/plain and text/xml.
While it's a good idea to whitelist the type of files that are compressed (no reason to attempt to decompress a file that is already compressed, such as image files, zips, etc), we are leaving out some important files we should compress too.
With the virus-like spread of scriptaculous, jQuery and a wide set of javascript tools, and the rather complex css files we are using nowadays it makes a lot of sense adding compression support for those types of files.
And its such an easy feat too! Just add the following to your webserver configuration:
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/javascript text/css
And restart with
[ -e /etc/init.d/httpd ] && /etc/init.d/httpd restart [ -e /etc/init.d/apache2 ] && /etc/init.d/apache2 restart
and that's it! All your website's files are now being transmitted using compression.
Want to see how much you gained from this? Add the following to your configuration and see the compression ratio achieved.
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
And have a look at the /var/log/apache2/deflate_log file to see the compression rate.
So what is the trade of of doing this? Just a little CPU time, you might want to check your system load to make sure your system's bottleneck is not the CPU before doing this.
Enjoy!