Top 3 Methods to Enable Gzip Compression in WordPress

Why Should We Enable Gzip Compression?

There are several benefits to enable Gzip compression because it’s the most popular method to load your site faster by reducing more than 70% page size of your blog. However, now-a-days most of the sites are using Gzip compression across the web. Gzip will load your site in just a few seconds.

Benefits

  1. Search more likely prefer you in search results
  2. Your server will no longer get large server requests to process
  3. 1000 KB page size will converted into 100KB

Enable Gzip Compression

Time to time there have been developed several resources to enable Gzip for WordPress sites. There are 3 methods to enable Gzip compression in WordPress following are these:

1. Enable Gzip using Existing (Maybe not) WordPress plugin W3 Total Cache

The most popular plugin (W3 Total Cache) which have a great role in improving your WordPress site performance, it also let you Gzip your site (To enable Gzip compression using w3 total cache, go to Performance > Browser Cache).

Enable Gzip via W3 Total Cache

2. Enable Gzip Compression via .htaccess

Gzipping an easy way to reduce weight per page of your site. You can enable Gzip compression by adding the following code to your .htaccess file:

# compress text, html, javascript, css, xml:
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
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png

Don’t know how to edit .htaccess file directly from WordPress dashboard, click here.

3. WP HTTP Compression Plugin

This plugin allows you to output the pages in Gzip compressed format. HTTP compression generally means a 60-80% reduction in the size of your pages. Follow these steps to enable Gzip for WordPress:

1. Download, install and activate WP HTTP Compression

2. There is no settings page by this plugin because it works automatically, further see if your site is working after the installment of this plugin here = IS MY SITE WORKING.

TaDan! It’s Done!

How People found this article:

About Muhammad Haroon

Truly yours, Muhammad Haroon is my name. Living in Karachi, Pakistan and enjoying my life playing with codes and blogging frequently, my most popular guides on Best WordPress Plugins. I founded Softstribe in 2012, when I was about to leave College. Find me on

79 comments

    1. Hi thanks for the comment and letting me know about the issue. Let me tell you that there is not any specific way but you can add the line of codes just after the #END WordPress in your .htaccess file.

      1. You should never add custom code in between the #BEGIN WordPress and #END WordPress lines.

        WordPress automatically generates this section and any time you make modifications to something like Permalink settings, everything you’ve added between these lines will be overwritten.

      2. I have been added it before End now my website is completely spoiled and not working shown 500 internal error even my wp directory also not working. please help me

  1. So I have enabled gzip with your code in the htaccess. I tested it with this tester and it worked.

    However, PageSpeed is still telling me to enable it and telling me which files should be compressed. So do I need to compress the files for this to work? How do I do this? And if I compress the files can I not edit them in WordPress as usual? For example, it wants me to compress main.css

    Thank you!

    1. If you have just enabled the Gzip compression then why the pagespeed testing tool is asking you to enable compression on main.css? I’m using the same method to gzip my entire blog. In this case use wp-minify plugin to minify the CSS files only.

  2. Thanks for the tip. I was getting a slow page speed at the Google Page Speed checker. After following your instructions I went from a 62 to an 87.

  3. Hello, I don’t know why but when I active ZIP compression using htaccess I can’t see any page on the blog (I’m exploiting Super WP Cache too), but I just download a zip file without seeing anything. Any idea about this ? Thanks for you post :)

    1. Your welcome, If you are using WP Super Cache make sure that it’s setup correctly in your WordPress blog.

      By the way, on adding the gzip codes in your .htaccess file the pages of your blog goes off as you said. Solution for this problem is that, you are using the multiple times compression options once the WP super cache compression option and the other one is by .htaccess file. You should use one time, rather than multiple, if you use multiple time compression option then they will conflict each other and the result would be the blank pages.

      Regards,
      Muhammad Haroon

      1. Hello, you got the idea, it seems that WP Super Cache was also compressing my website files: so you should just choose, using htaccess manually or check plugin option for compression (and they say as notice, there is no WARRANCY that all will be ok).

  4. Great post! I was already using the option “Compress pages so they’re served more quickly to visitors. (Recommended)” of wp-super cache checked. This option enables also enables gzip, but my grade was really bad on yslow and PageSpeed told me to make the gzip compression.

    When I used your second method Google PageSpeed told me: You have compression enabled. And Yslow gave me a C Grade. 72% and 92% on GTmetrix.

    Is there any problem using WP Super Cache method plus .htaccess from ur post?

    Cya

  5. “2. Enable Gzip Compression via .htaccess

    Gzipping an easy way to reduce weight per page of your site. You can enable Gzip compression by adding the following code to your .htaccess file:”

    That simple, huh? When the host doesn’t allow mod_deflate, nothing will happen, right?

    1. HI @Jeroen,

      Yes, you are right. But still you can use the third way of enabling gzip compress:

      3. WP HTTP Compression Plugin

      This plugin allows you to output the pages in Gzip compressed format. HTTP compression generally means a 60-80% reduction in the size of your pages. Follow these steps to enable Gzip for WordPress:

      1. Download, install and activate WP HTTP Compression

      2. There is no settings page by this plugin because it works automatically, further see if your site is working after the installment of this plugin here = IS MY SITE WORKING.

      TaDan! It’s Done!

      1. Thanks Muhammad, I’m going give this a try since I have been spending hours on getting the gzip working via htaccess and W3 Total Cache (and other plugins)

    1. Hi @Sohil Memon,

      Thanks for the commment, and by the way manual process would be fine enough… Through .htaccess file, rather than using the third method of gzip compression… Okay. Hope you understand.

  6. I added the code and my website speed did not increase at all? Am i doing something wrong? My speed from google is 52/100 its really hurting business

  7. Thank you SO much for the Gzip compression code for the .htaccess file. I was running a 21/100 and 25/100 for mobile/desktop page load tests via PageSpeedTest insights on Google Developers. I’m now at 55/100 and 68/100 respectively. Your Gzip code fixed the majority of my slow response time. Now my host just needs to get their act together and get my server running more smoothly. Thanks so much.

  8. Hello,

    This is the article I have been looking for. Thanks for the information.

    I added the code in my .htaccess. However, there is no difference in the speed test or google page speed test. What could be the problem, I really prefer the htaccess option

    Do you think I should try to install WordPress plugin W3 Total Cache or the WP HTTP Compression Plugin? Do you have any preference

  9. Hello

    Thanks for the post.

    I added the code that you provided to my .htaccess through ftp edit.
    But, no change in the page speed.
    Any suggestions

      1. Hi,

        I installed the w3 total cash and performance improved. Option 1. Thanks for that.

        My question now is I want some pages not to be cached and I want to add it in the Never cache the following pages section

        what is the format /my-account/* or my-account/* or the faq says something like /my-account/.+

        appreciate your help

  10. Hey Muhammad, thanks a lot for your great post. I was just wondering: would you recommend doing all three of these methods at once – or should you only do one at a time? And if you should, which one method would you recommend the most?

    1. Your welcome @James on my blog, but I recommend you to use one method at a time rather doing all at once. And by the way, the method that I would recommend you the one using .htaccess file. Hope you understand. Keep visiting my blog thanks.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>