Knowledgebase

How to enable compression with mod_deflate

Mod_deflate is an Apache module that is used to compress the data transferred from the server to the client. This is an optimization measure that you can use to speed up your site and reduce the bandwidth.

All HostKnox servers have mod_deflate installed. To use it you just need to enable it by putting some directives in an .htaccess file. If you want all the content that can be accessed by web visitors to be compressed, put the directives in the .htaccess file that's in the public_html directory on your hosting account. You can edit the file from the Files section of the Pixie control panel; just click on the file's name, put the directives on a new line and save the file. If you don't have an .htaccess file in the desired folder (e.g. public_html) you can also create it from the Files section of the Pixie control panel; simply use the Create File button that's in the black area on the right.

Put the following rules in the .htaccess file:

<ifmodule mod_deflate.c="">
    SetOutputFilter DEFLATE
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript application/dx-javascript
    AddOutputFilterByType DEFLATE application/x-httpd-php
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|zip|gz)$ no-gzip dont-vary
</ifmodule>

The AddOutputFilterByType directives list all the file types that should be compressed before being transferred from the server to the client's browser. After they are transferred the browser uncompresses them and the webpage is displayed.

There are some additional instructions with the BrowserMatch directives. In this case they are for the browser Netscape Navigator version 4.x which has problems with uncompressing content. Depending on the particular version, if this browser is used by the client either only text/html files will be gzipped or no compression will be applied.

Was this answer helpful?

 Print this Article

Also Read