Why and How to Enable Gzip Compression in WordPress?

Aug 17, 2015

If you’re familiar with adsense, then you probably know by now that one way to improve the PageSpeed Insights score is to enable compression. For this purpose you can use Gzip compression which reduces the transferred response and speeds up your website significantly.

What is Gzip compression and how does it work?

Gzip basically compresses most of the files of your website before sending them to the browser of the user that’s visiting your website. When a user visits your website, a call is sent to your server to deliver the appropriate files and if the files are too big then the transfer will take a really long time to complete. By compressing your files with Gzip, you can reduce the size of your files and the transfer time by up to 70%.

The way that Gzip works is, it locates strings that are similar and replaces them temporarily and this works especially well for HTML and CSS files because they use a lot of repeatable text and whitespaces. When the user’s browser make a request to your server for your website’s content, if you’ve enabled the Gzip compression, your server will send the Gzip content which is smaller than your normal files and the transfer will be way faster. If not, your server will send your non-compressed page and the pages will load slower.

How to Enable Gzip Compression in WordPress

Why you should enable Gzip compression in WordPress?

The main thing why you should enable Gzip compression for your is to increase your page speed. This is a great thing to do if you want to optimize your website for the search engines or to increase your PageSpeed Insights score on adsense.

Enable Gzip Compression in WordPress with .htaccess

Enabling Gzip compression with .htaccess is really simple to do and you can do it even if your website isn’t using WordPress as a CMS. If you’re using Apache server, just log in into your CPanel or access your .htaccess file through a FTP client software of your choice and open your .htaccess file (if you don’t have a .htaccess file create one) and add the following lines:

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

These lines should be enough to do the trick.

Enable Gzip Compression in WordPress with plugin

Another way to enable Gzip compression in WordPress is by using a plugin. There are couple of plugins out there but probably the most popular one that almost everyone uses is W3 Total Cache. Here’s step by step guide on how to enable Gzip compression in WordPress using the W3 Total Cache:

  1. Download, install and activate the plugin.
  2. After activating it, on the bottom on the left admin menu in WP you’ll see a new tab called Performance.
  3. Go to Performance > Browser Cache
  4. Check every box that says Enable HTTP (gzip) compression.
  5. That’s it, you’re done!

So, these are basically the two simplest ways to enable Gzip compression in WordPress. Do you know any other ways of enabling Gzip compression?

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *