Enabling GZIP compression for website.

In this article, I will explain how to enable GZIP compression. GZIP compression will help us to improve the site speed by compressing the site content before it serving to visitor’s browser.  If your site page size is  100kb or more, then GZIP compression is the great option to improve the performance. It also helps to reduce bandwidth usage, thereby reducing HTTP response.


You can enable GZIP compression by two methods.

  1. By directly adding  rules to .htaccess file present under your site document root

## enable apache served files compression

## http://developer.yahoo.com/performance/rules.html#gzip
# We check for the module just in case
<IfModule mod_deflate.c>
    # Insert filter on selected content types only
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary


You can adjust which file types are compressed by modifying “deflate” command. Some examples:-

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x- javascript application/javascript application/x-font-ttf

or to compress everything except images

#Insert filter on all content
SetOutputFilter DEFLATE
 # Don't compress images
 SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

2. You can enable directly from cPanel.

Login to cPanel -> Software -> Optimize website

Optimize website in cPanel X3 theme.

Optimize website in cPanel paper_lantern theme.



Leave a Reply

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