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. Before enabling compression check that zlib.output_compression is enabled by using the Select PHP Version tool. For complete instructions on changing PHP settings, please see this article.
  3. Open the Optimize Website tool:
    • If you are using the Jupiter theme, on the Tools page, in the Software section, click Optimize Website:

      cPanel - Software - Optimize Website icon

    • If you are using the Paper Lantern theme, in the SOFTWARE section of the cPanel home page, click Optimize Website:

      cPanel - Software - Optimize Website icon

  4. 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.
  5. 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://www.giftofspeed.com/gzip-test, type your domain name in the text box, and then click CHECK. 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.4/mod/mod_deflate.html.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.