Knowledge Base

How to enable data compression using the mod_deflate module

This article describes how to enable data compression using Apache's mod_deflate module. You can use the mod_deflate module to compress output from your web site that is sent to client browsers. Using data compression can reduce page load times and the amount of bandwidth your site uses.

  • Older versions of Apache used the mod_gzip module for data compression. In practice, the mod_deflate module for Apache 2 provides the same functionality as the mod_gzip module.
  • The mod_deflate module is already installed on shared hosting accounts, and we can install it on managed VPS and dedicated servers as well at your request. If you need further assistance, please open a support ticket with our Guru Crew on the Customer Portal at https://my.a2hosting.com.

cPanel (managed) hosting accounts

To enable data compression on cPanel-based hosting accounts, follow these steps:

  1. Log in to cPanel.
    If you do not know how to log in to your cPanel account, please see this article.
  2. In the SOFTWARE section of the cPanel home screen, click Optimize Website.
  3. On the Optimize Website page, under Compress Content, select one of the following options:
    • Compress All Content: Select this option if you want to compress all of your content.
    • Compress the specified MIME types: Select this option if you want to compress specific types of content. In the MIME Types text box, type the MIME types that you want to compress.
      To view a complete list of MIME types, please visit https://www.iana.org/assignments/media-types/media-types.xhtml.
  4. Click Update Settings. The new settings take effect immediately. To verify that data compression is active, please see Determining if compression is enabled below.

Unmanaged hosting accounts

For unmanaged hosting accounts, you must edit the .htaccess file to enable data compression. The following sample configuration demonstrates one way to enable data compression by specifying file extensions:

<IfModule mod_deflate.c>
    <filesMatch "\.(js|css|html|php)$">
        SetOutputFilter DEFLATE
    </filesMatch>
</IfModule>

In this example, Apache compresses any file that has an extension of .js, .css, .html, or .php.

Alternatively, you can use MIME types to specify which files to compress. The following sample configuration demonstrates one way to do this:

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>

In this example, Apache compresses any file that uses one of the MIME types referenced by the AddOutputFilterByType directive.

To view a complete list of MIME types, please visit https://www.iana.org/assignments/media-types/media-types.xhtml.

To disable data compression, you can delete the relevant lines in the .htaccess file, or comment them out by preceding each line with #.

To verify that data compression is active, please see Determining if compression is enabled below.

Determining if compression is enabled

To check if data compression is enabled on your site, go to https://checkgzipcompression.com and type your domain name in the text box. The site tells you whether or not compression is currently enabled.

More Information

For more information about the mod_deflate module, please visit http://httpd.apache.org/docs/2.2/mod/mod_deflate.html.