The article explains how you can enable data compression by using Apache’s mod_deflate module. mod_deflate module can be used to compress output from your website that is sent to client browsers. Using data compression reduces page load times and the amount of bandwidth that your site uses.
All the older versions of Apache used the mod_gzip module for data compression. Practically, the mod_deflate module for Apache 2 provides the same functionality as the mod_gzip module.
# Steps to enable data compression on cPanel managed hosting account
1) Log into your cPanel.
2) Before proceeding to enable compression, first check that zlib.output_compression is enabled by using the Select PHP Version tool.
3) On the cPanel home screen go to the SOFTWARE section and click on Optimize Website.
4) On the Optimize Website page, under the Compressor Content heading, select one of the below options :
• Compress All Content: If you wish to compress all of your content then select this option.
• Compress the specified MIME types: To compress the specific content, select this option. In the type box for MIME Types, type the MIME types that you want to compress.
View a complete list of MIME types by visiting :
https://www.iana.org/assignments/media-types/media-types.xhtml
5) Click on Update Settings.
The new settings will be effective immediately. In order to verify that data compression is active, see Determining if compression is enabled below.
# For unmanaged hosting accounts
For the unmanaged hosting accounts, you need to edit the .htaccess file to enable the data compression. Following is a sample configuration that demonstrates one way to enable data compression by a specific file extension:
<filesMatch "\.(js|css|html|php)$"> SetOutputFilter DEFLATE
In this example, the Apache will compress all the files having an extension of .js, .css, .html and .php.
Otherwise, you can also use MIME types to specify which files need to be compressed. Following is a sample configuration that demonstrated one way of doing this :
<IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css text/javascript application/javascript </IfModule>
In this above example, Apache will compress any file that uses one of the MIME types referenced by the AddOutputFilterByType directive.
View the complete list of MIME types by visiting :
https://www.iana.org/assignments/media-types/media-types.xhtml
To disable the data compression, you can delete the relevant lines in the .htaccess file, or can comment them out by starting each line with #.
You can verify that data compression is active, by viewing Determining if compression is enabled below.
Get more information about the mod_deflate module at :
http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
Also Read :
1) What is CloudFlare Railgun and How to Enable it on Your Website?