enable GZIP compression
Enabling the GZIP compression is the best way to speed up your WordPress website. In this tutorial, I will show you how to enable GZIP compression on WordPress website. Well, it is an easy process which will hardly take 10 minutes.
What is GZIP Compression?
It is basically a type of compression which is used to load your website elements faster than usual. Suppose if you’ve enabled GZIP compression on your website, this will gradually decrease your page size to half. Isn’t it amazing? The drawback of using this technique is, sometimes you may feel that your website has lost some of its visual qualities.
This is one of the greatest factors of SEO too. As you all know, that Page speed has become one of the important ranking factors of SEO. You might like this great post by my mate Satyansh, How your website speed affects SEO.
If you have not enabled GZIP compression do it now because there are many others in the competition. And if you’re slow you’re weak. To check that whether you have already enabled GZIP compression on your website visit this link. Because some of the web server providers enable it by default.
GZIP can easily be implemented on any WordPress website by adding some codes to your .htaccess file.
Note : .htaccess file is very sensitive file and before making any change make sure you’ve downloaded it.
There are many other methods too but let’s start with the simplest one 🙂
GZIP Compression can be enabled differentially for different web servers. Mostly the file structure of a .htaccess file for Apache and NGINX web servers are different. Hence, there are variations in its functions too.
Enabling GZIP compression with .htaccess file
.htaccess file is a very sensitive file of your web server. Basically, this file controls all the information to be viewed by the visitors and non-admins of your website. Before making any changes to your .htaccess file I recommend you to download it safely to your computer.
You cannot edit your .htaccess file using WordPress. For that, you’ll have to login into your CPanel and after that, you’ll find a file named “.htaccess” in your public_html folder. Open the file “.htaccess” paste this code (given below) in the beginning.
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_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
After adding this code to your website hit the save button and try reloading the Web page. Consider to clean your website cache so that it can take effect more gracefully. It will definitely work for your website.
Enabling GZIP compression on Apache web servers
The code above should work for Apache web servers. If somehow it is not suitable or not working properly on your site then you can try this one. Before adding this consider removing the above one.
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
Check that whether this code working on your website. Either of this code will definitely work on your web server.
The codes mentioned above are only applicable for Apache web servers (not NGINX)
Enabling GZIP compression on NGINX web servers
For activating GZIP compression on NGINX web servers copy the code given below and paste it into your configuration file.
gzip_buffers 16 8k;
# 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
To test that whether the above methods are successfully working for you : check for GZIP compressions.
I will not recommend this method, absolute beginner. If you’re an absolute beginner and don’t know much about codes, you can install this plugin which may help you in GZIP compression of your website elements.
By adding this function to your website, it will definitely run faster. Happy Blogging.
You may also like: How to speed up your WordPress website?