What is Compression?

Compression is a process which decrease the file size and load your website faster to the users. Compression of HTML and CSS files reduce the sixty to seventy percent size of your website and user enjoy the fast loading speed of website in low bandwidth.

enable gzip compression optimize website

Now a days if you does not increase your website speed your competitors will beat you in google competition. Google give more importance to website which loads faster that’s why google has a tool where you can check website speed PageSpeed Insights.

In this google tool you will find some good suggestion to increase your website speed it will let you know how you can enable gzip compression.

How to Enable gzip compression

There are several methods to enable gzip compression.

Here are the some easy steps to enable gzip compression via .htaccess, Apache, Nginx, and Litespeed webservers.

Enable compression via .htaccess

You just need to copy this code and paste in your .htaccess and save.

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

There are different online tools where you can test you website has enable 
gzip compression or not Gzip compression tool.

Enable compression on Apache webservers

If above mentioned code not work in your website there is another method to enable gzp compression. Remove previous code and paste the below mentioned code.

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

Enable compression on NGINX webservers

To enable gzip on your NGINX server copy and paste this code in your config file.

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;

# Disable for IE < 6 because there are some known problems
gzip_disable "MSIE [1-6].(?!.*SV1)";

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;

About The Author

Related Posts

Leave a Reply

Your email address will not be published.