How to enable compression using htaccess

Enabling compression will increase the performance of websites a lot.

In-order to enable the compression, apache compression module deflate should be installed. If you own the application server, you can install this module directly and other wise need to contact the hosting support for installation.

Once the deflate module is installed, we need to add the following lines to the .htaccess file inside application root folder.

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

This will enable the compression for application. We can verify this using the Gtmetrix online checker.

https://gtmetrix.com

The above htaccess rule will help to get A grade in compression section while checking through Gtmetrix.

That's all…

Leave a Reply

Your email address will not be published. Required fields are marked *