Mod_deflate is a module for the Apache Web Server. Its purpose is to make a better use of the available bandwidth by compressing content delivered from the web server to the client's browser. The compression is automatic, and the only requirement is that the browser supports gzip compression. Nowadays, most of the browsers support gzip, and no additional software is required.

  • How is the compression performed?

The browser will announce if the compression method is supported when sending a request to the server for a specific file, for instance, http://www.example_domain.com/index.html. In case Apache is configured with mod_deflate, the content of index.html will be compressed and sent to the browser. The browser, on the other hand will decompress the gzip file and will display it to the client as a simple html file. The web visitor would not be aware of the above operations.

  • How can I use mod_deflate?

To set up mod_deflate, you have to create a .htaccess file (note the dot(".") at the beginning of the file) with the following code in it:

<IfModule deflate_module>
    AddOutputFilterByType DEFLATE text/css text/csv text/html text/plain text/richtext text/sgml text/tab-separated-values application/javascript application/x-javascript httpd/unix-directory
    AddOutputFilter DEFLATE html htm shtml php php4 pl rb py cgi css js txt
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

Then save the .htaccess file to the directory where you want mod_deflate enabled. Have in mind that .htaccess files work recursively, so it will have effect on all the subdirectories as well.

The .htaccess file above will have mod_deflate enabled for all HTML, SSI, PHP, Perl, Ruby, Python, CGI, Cascading Style Sheets, JavaScript and text files.