How to Enable Gzip Compression in WordPress to Increase Site Speed
What is Gzip Compression?
Gzip Compression is a method which compresses files(make them smaller) and increases the speed to which they are transferred to the browser.
For example, When a user visits or clicks on your website, a call is made to your server to deliver the requested file. Requested files are counted the total number of articles and files on your page, which includes images, ads, widget, scripts, HTML, CSS, Java scripts etc. The bigger files you have, the more time it will take to appear on your screen. That why here comes the one of the best method called Gzip Compression. In this tutorial, I am showing you how to enable Gzip Compression.
Why you need to Enable Gzip Compression on Your WordPress Website
As i mentioned above that Gzip Compression is one of the best way to optimise your website and also increase your page speed. It compresses your webpages and style sheets before sending them over to the browser. So if the total size of page is 100 KB , then only 10 KB file are sent to the browser. There are some benefits you are getting of using this, such as:
- Compress 100 KB file to 10 KB
- Reduces Page sizes & Increase page speed
- Cost-benefit ratio: high
Simply you can check your page speed using GTmetrix. This tool will show you is your server Gzip Compression enabled or not. There is another Gzip Compression checker tool you can use, Check GZIP compression.
You can see that 76% was saved by compressing this page with GZIP. The primary size of uncompressed files was 30,599 bytes, and after compressed it is now only 7,350 bytes.
This Gzip Compression process is totally free, so you don’t need to buy a service or any tool. You just need to have access to the .htaccess file.
How to Enable Gzip Compression in WordPress
There are several ways to enable Gzip Compression on webservers. You can enable it from .htaccess, NGINX and use plugin.
Enable Gzip Compression via .htaccess (Recommended)
For this method, you will need to access to your cPanel. In the WordPress root folder, add the following lines to .htaccess file.
[code]
## ENABLE GZIP COMPRESSION ##
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 GZIP COMPRESSION ##
[/code]
Save the .htaccess file and then refresh your web page. Now test your site again in GTmetrix or here to make sure it has been properly compressed.
Enable Gzip Compression on NGINX web servers
To enable compression in NGINX you will need to add the following code to your config file.
[code]
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;
[/code]
Enable Gzip Compression using Plugin
Download GZip Ninja Speed Compression plugin and activate from your Admin Dashboard. Then go to Tools> Gzip Compression and simply enable it. No further setup required.
I hope this tutorial helped to enable Gzip Compression. Gzip Compression is one of the most important optimization processes for websites. If this helped to increase site speed, please share this topic on Facebook, Twitter, Google+.
Related Articles,
- 19 Best Tips to Speed Up WordPress(Increase Site Speed by 200%)
- 20 Best WordPress Plugins 2017: Essential for Professional Bloggers
- How to Minify HTML, CSS and JavaScript Using Autoptimize Plugin
*This post may have affiliate links, which means I may receive a small fee if you choose to purchase through my links (at no extra cost to you). This helps us to keep WPMyWeb up and running and up-to-date. Thank you if you use our links, we really appreciate it! Learn more.