Enabling Gzip Compression in WordPress via .htaccess reduces Server Response Time and volume of data sent by the server to web browser. Certainly, compressed page size help reducing the transferred response and data. The best way to enable compression is, using mod_gzip or mod_deflate in WordPress .htaccess file. And the good news is, Gzip compression can be enabled by adding a simple code in WordPress .htaccess file of your website.
Don’t worry if you don’t want to enable compression via .htaccess file. Because I have also explained how to use the best plugins like W3 Total Cache, WP Super Cache to enable Gzip compression in WordPress.
What is Gzip Compression?
How does it work?
The concept of Gzip compression is quite easy. It uses an algorithm which organizes repeated strings in a single place only, instead of saving those same strings again and again. And it manages those strings with their location values while compression and retrieving data back from compressed files. Gzip compression works very well with stylesheets and webpages because all these resource files have many repeated strings. Because of its compression technique, Gzip may reduce the file size by 70-90%.
Let’s have a look on the given below example to understand the Gzip Compression…
Suppose if your HTML file contents following strings…
<h3>Enable Gzip Compression in WordPress </h3>
Then, the compressed file will look like this.
But if your HTML file contents repetitive strings as following…
<h3>Enable Gzip Compression in WordPress</h3>
<h3>Enable Gzip Compression in WordPress via .htaccess</h3>
Then, Gzip compresses the repeated strings once and uses the latter part of your HTML file.
If you are working on pagespeed of your WordPress site then you should apply these too:
- Remove Query Strings from Static Resources to Increase your Website Speed
DEFLATE Compression and Gzip Compression in WordPress
You might have read on the web about Gzip Compression and DEFLATE compression. If you haven’t, let me tell you about them in nutshell. Both compression algorithms (Gzip and DEFLATE) are different and used for different servers. Gzip compression is used on Apache and Nginx servers, while DEFLATE is only used on Apache servers.
Before You Start
First, you should check whether Gzip Compression is enabled or not on your WordPress site. Google Gzip compression test tool or you may use this one. If compression is already applied to your site. Then you may check if compression is enabled properly. Or is there still scope for better compression? (the technique which reduces the files size most is better).
You also need to find out which web server software (Apache or Nginx) your web host is using. Because Gzip Compression method is different for both servers. You also need to figure out, how to edit WordPress .htaccess file if you are using Apache Server. Here is a detailed guide How to edit WordPress .htaccess file easily you may refer.
Enable Gzip Compression in WordPress via .htaccess
To enable Gzip Compression in WordPress via .htaccess, you only need to copy and paste given below code in WordPress .htaccess file and save changes. Now check your site on compression testing tools again. It will definitely reduce your website page size significantly and will increase page-load speed.
Compression on Apache server
- Gzip Compression – Add following code in WordPress .htaccess file of your website.
- DEFLATE Compression – Copy and paste the following code in WordPress .htaccess file of your website.
Compression on Nginx server
- Gzip Compression – Paste the following code in the configuration file of your website hosted on Nginx server.
Results after Applying Compression
My blog TechNumero was hosted on Apache server, so I was using Gzip compression and DEFLATE compression both on my website. And it is reducing webpage size by 82.2%. Initially, my web page size is 42,656 Bytes (without compression) and after compression, my web page size is 7,596 Bytes only. Hence, I managed to save 35,060 Bytes using Gzip Compression on Technumero.com.
Gzip Compression with WordPress Plugin – W3 Total Cache
W3 Total Cache is one of the most used caching plugins on WordPress platform. And if you are using this plugin, you can enable Gzip compression via this plugin. Follow the given below steps to enable Gzip compression with WordPress Plugin – W3 Total Cache
- Go to the W3 Total Cache Plugin Settings page
- Navigate to Browser Cache page
- And Check the Enable HTTP Compression option
- Don’t forget to click on Save changes button and you are done.
Gzip Compression with WordPress Plugin – WP Super Cache
WP Super Cache is another popular caching plugin. And you can enable Gzip compression with just one click using this plugin. Use the given below steps to Enable Gzip compression with WP Super Cache plugin.
- Navigate to the WP Super Cache Plugin Settings page
- Click on the Advanced Tab and
- Now Enable the First option in Miscellaneous settings
- Save the changes and you are done.
Wrapping it Up
Gzip Compression is one of the most used technique for file compression. In addition to that, it is also one of the most recommended methods by pro bloggers for PageSpeed Optimization. Nowadays, Gzip Compressions comes enabled by default with few modern web hosting servers. However, if it is not enabled on your server, now you know, how to enable Gzip Compression. Feel free to fire your queries via the comment section below. Do let us know, how much file size you have reduced by enabling Gzip Compression?
In addition to that you may be interested to read following tutorials: