This article describes the way to enable data compression using Apache's mod_deflate module. You’ll use the mod_deflate module to compress output from your website that’s sent to client browsers. Using data compression can reduce page load times and the amount of bandwidth your site uses.
cPanel (managed) hosting accounts
To enable data compression on cPanel-based hosting accounts, follow these steps:
1. Log in to cPanel.
2. Before enabling compression check to see that zlib.output_compression is enabled by using the Choose PHP Version tool.
3. In the SOFTWARE section of the cPanel home screen, click Optimize Website:
4. On the Optimize Website page, under Compress Content, choose one of the following options:
- Compress All Content: Choose this option if you want to compress all of your content.
- Compress the required MIME types: Choose this option if you want to compress specific sorts of content. In the MIME Types text box, type the MIME types that you want to compress.
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 a method to enable data compression by specifying file extensions:
In this example, Apache compresses any file that has an extension of .js, .css, .html, or .php.
Alternatively, you’ll use MIME types to specify which files to compress. The following sample configuration demonstrates a method to do this:
In this example, Apache compresses any file that uses one of the MIME types referenced by the AddOutputFilterByType directive.
To disable data compression, you’ll 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, type your domain name in the text box, then click CHECK. The site tells you whether or not compression is currently enabled.