How To Enable Gzip On Your Website Or Blog

By | December 16, 2015

GZIP

Gzip is a software application as well as a file format which is basically used for file compression and decompression. In this post, we will be talking about Gzip’s function only in relation to websites.

Basically, what happens is, when you try to visit a website, your web browser sends a request to the website’s server for content and it is then checked whether Gzip is enabled or not. If it is not enabled, then the server sends the files in the old school way and there is no benefit received. The website does not load faster. But, if Gzip is enabled, then the server sends the encoded Gzip content to the browser which is then decoded and displayed to you. In this case, the website loads faster because the encoded Gzipped content is very much less in size than the original website files. :) :) :)

How does Gzip work

 


Let’s begin, shall we? First, check whether Gzip is enabled on your website or not. You can do this by visiting ‘Gzip Test‘ or ‘Check GZIP Compression‘ and testing your website there. If it is not enabled, continue reading!

The method of enabling Gzip will be different for different website servers. You’ve got to determine which method you need to be following. To do so, find out what are your website’s servers are running on – Apache, Nginx or Litespeed. If you do not know anything about this, ask your website hosting service provider and they will gladly tell you. If you do not wish to wait that long, visit ‘Gzip Test‘, test your website there and it will also tell you what is your website’s server running on. If your website’s server is running on any web server software other than the three mentioned above, then this post is not for you. However, you may comment below mentioning the details of your web server’s software and I’ll be happy to help you out. :) :) :)

Note: Although WordPress users can install a plug-in on their websites/blogs to enable Gzip, I would recommend not doing so as it is completely unnecessary to use a plug-in for such a task. Enable Gzip the old school way which will be shown below.

 


METHOD FOR ENABLING GZIP ON A WEBSITE RUNNING ON APACHE:

You will need to add the following code to your ‘.htaccess’ file in your website’s root directory. For those who do not know about the ‘.htaccess’ file, just know that ‘.htaccess’ file controls many settings for your website. Just open your file manager or use your FTP client to go to root directory of your website and look for a ‘.htaccess’ file (if you are not able to find it, make sure that hidden files are viewable as well), open it for editing and paste the code given below in it and save it. If you are sure that there is no ‘.htaccess’ file, just open up notepad, paste the below code in it, save it as ‘.htaccess’ (make sure the ‘Save as type’ is set to ‘All Files (*.*)’) and upload it to the root directory of your website. That is all! :D :D :D

# Enable GZIP
<IfModule mod_deflate.c>
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
</IfModule>

 


METHOD FOR ENABLING GZIP ON A WEBSITE RUNNING ON NGINX:

To enable Gzip compression on servers running on Nginx, you will need to add the code shown below to your config file which should be located somewhere like ‘/etc/nginx/nginx.conf’ or ‘/usr/local/nginx/conf/nginx.conf’ in most of the distributions.

# Enable GZIP
gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Disabling GZIP for IE6 and lower versions due to problems
gzip_disable "MSIE [1-6].(?!.*SV1)";

# Avoiding cached GZIP files to be sent to IE6 and lower versions due to problems
gzip_vary on;

 


METHOD FOR ENABLING GZIP ON A WEBSITE RUNNING ON LITESPEED:

Method I) The theoretical way to enable Gzip compression on Litespeed webservers is by doing it through the configuration under ‘Tuning’. Go down to ‘Enable Compression’ and check to see whether it is on or not. If it is not on, click ‘Edit’ and then choose to turn it on. You may also have a look at the several other Gzip options which are present nearby.

Method II) There is also another method you can follow to enable Gzip on your website which is running on LiteSpeed. You will need to add the following code to your ‘.htaccess’ file in your website’s root directory. For those who do not know about the ‘.htaccess’ file, just know that ‘.htaccess’ file controls many settings for your website. Just open your file manager or use your FTP client to go to root directory of your website and look for a ‘.htaccess’ file (if you are not able to find it, make sure that hidden files are viewable as well), open it for editing and paste the code given below in it and save it. If you are sure that there is no ‘.htaccess’ file, just open up notepad, paste the below code in it, save it as ‘.htaccess’ (make sure the ‘Save as type’ is set to ‘All Files (*.*)’) and upload it to the root directory of your website. That is all! :D :D :D

php_value output_handler ob_gzhandler

 


Now, if you have follow the method shown above for your web server correctly, Gzip should be enabled. Visit ‘Gzip Test‘ or ‘Check GZIP Compression‘ and test if your website has Gzip enabled now or not. Normally, it should get enabled right away! But if it does not get enabled, you might try emptying your website’s cache and testing your website for Gzip after some time. If it is still not enabled, comment below explaining exactly what you did and I’ll be more than happy to help you out. :) :) :)

Also, if you find this method of enabling Gzip helpful, share it with your friends having their own website or blog.

Thank you.

LINK TO THIS POST:

<a href="https://www.theadarshmehta.in/blog/how-to-enable-gzip-on-your-website/2015/12">How To Enable Gzip On Your Website Or Blog</a>

Spread the love

One thought on “How To Enable Gzip On Your Website Or Blog

  1. Jewel

    Excellent article. I have seen many articles enabling gzip but here, I have found “php_value output_handler ob_gzhandler” and it works. Thank you very much for writing some helpful article.

    All the best

    Reply

Leave a Reply

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