Mod_deflate is an Apache module which can be used to compress files before sending them to clients. If configured correctly, mod_deflate can offer substantial bandwidth savings.
Mod_deflate can be used to compress HTML, CSS, XML and other text files, reducing page loading times for users and reducing your server’s bandwidth consumption. There is some small performance overhead for compressing files, but on modern servers the overhead should be negligible compared to the reduction in loading time from the file size reduction.
Setting Up Mod_Deflate
In most cases, mod_deflate comes with Apache2 platform, so all you have to do is enable it, and then restart Apace2 by entering the following in the command line:
The above instructions are for Debian and related distributions (e.g. Ubuntu). If you are running a RHEL distribution you may need to edit Apache’s configuration files manually and add deflate_module to the LoadModule section of the file.
The next step is to configure mod_Deflate. In most cases, you should only compress text and HTML files. Add the following to your config file to do this:
AddOutputFilterByType DEFLATE text/html text/plain
Another option is to set up mod_deflate to compress all files, except for files which are explicitly excluded, such as already compressed ZIP files. There is no point attempting to compress a ZIP or TAR.GZ file because these files have already been compressed once and it is unlikely that you would save much (or any) bandwidth by compressing them again.
Once you have finished configuring mod_deflate, you should restart Apache again. The compression occurs silently. If you want to see how well it is working, you can enable logging on mod_deflate, request a few files, and then open the log file to see a report of how well each requested file was compressed.