How to Enable Gzip Compression

Enable Gzip Compression
Standard

Enable Gzip Compression – In this tutorial we will discuss how to enable Gzip Compression feature on your web server so that it can increase the speed of your website. There are two ways to activate Gzip Compression by configuring the cpanel or changing the .htaccess file.

What is Gzip Compression

Gzip is a method of compressing files (reducing file size) so that data transfer over the network is faster and loads your site in just a few seconds. Gzip Compression is the most popular method for making your website faster by reducing more than 70-90% (claims from the Google Developers site) the size of your web page / blog. Gzip can compress CSS, JavaScript and HTML file types. Currently most websites have used Gzip Compression. Gzip Compression is one of the parameter evaluations on Google PageSpeed Insights and Yahoo YSlow.
There are several benefits obtained by activating Gzip Compression.

Advantage Enable Gzip Comppression

  • Preferred by search engines.
  • Your server no longer has a large request to process.
  • The size of your website will be reduced by 70-90%.
  • Increase the load speed of your website.

How it Works?

Gzip is actually a fairly simple idea that is very powerful when used properly. Gzip places the same string in a text file and replaces the string temporarily to make the whole file size smaller.

The reason gzip works well in a web environment is because CSS files and HTML files use a lot of repetitive text and have lots of spaces. Because gzip compresses common strings, it can reduce page size and style sheets to 70-90%!

When the browser visits the web server, the browser will check and see if the server has activated the gzip compression method and then asks for a web page. If gzip is activated, the browser will receive a smaller gzip file and if gzip is not activated the browser will receive a much larger file.

How to Enable Gzip Compression

Apache

Make sure the mod_deflate module is active on your server then paste or add the script below to your .htaccess file

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>

For cPanel users, you can activate it through the menu in cPanel. Next is how to activate Gzip Compression on your Cpanel:

  1. Login to your cPanel
  2. Navigate to “Optimize Website”
    How to Enable Gzip Compression
  3. Chose Compress all content and click Update Settings.
    How to Enable Gzip Compression

Nginx

Insert or add the script below to your .htaccess 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;

After enable Gzip Compression you need to check whether Gzip Compression is enable or not, to check it, you can use online tools bellow:

That’s it, hope you can get it all running without a problem, and enjoy your webiste speed.
By the way, don’t forget to subscribe my blog. It should giving you much information.

Advertisements