|

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:

[sociallocker]

Download PDF

[/sociallocker]

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.

Related  How to Replace WordPress Visual Editor with CKEditor

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!

126 Comments

  1. Hi
    Where should I add the following code to my .htaccess file (place) is there any specific place?

    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

  2. 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.

  3. 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.

  4. 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).

        1. Well, you got it right brother. You should only use the manual method and uncheck the option from WP Super Cache. It’s that easy solution for your problem.

          Muhammad Haroon

  5. 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

  6. “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)

  7. Thanks for the plugin Sir. But can I use this simple plugin? wordpress.org/plugins/wordpress-gzip-compression

    Do check it out and please tell me! Thanks in advance.

    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.

  8. 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

  9. 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.

  10. 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

  11. 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

  12. 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.

  13. I used the Yoast SEO method you suggested. I got an increase of 13 points. It was simple, easy and worked. Yeah, you the man bro…

  14. Thanks a lot for sharing this wonderful tutorial or I would say article. It is the best plugin ever transfer google speed insight rank dramatically for me.

  15. Nice tutorial, but how come you don’t have gzip compression enabled in your own site too? This page took forever to load.

  16. Amazing after using gzip compression in my blog my blog website speed decrease form 5 second to 3.2 second. Thanks.

  17. some apache servers has a optimize website / compress content setting.

    Will this work without the 3 methods above ??

  18. hi. I installed WP hTTP Compression plugin . Bt page insights still shows to enable compression. how do I eliminate this problem? It mentions specific files to compress.

  19. Th post was really helpful. Even though i use W3 total cache plugin, i was unaware that it is useful for compression as well.
    Thank you very much.

  20. Hi,
    Thanks dude for the great content. Enable gzip compression improve to load your site faster.
    But I have installed the w3 total cache plugin and also added the above code into .htaccess file but still didn’t worked for me… please tell me how can do that??

  21. Thanks for this awesome tutorial. I had my PageSpeed score from 81 to 89! That’s great! Thanks.

  22. I have enabled Gzip compression using Total Cache. But GTMetrix still asks me to enable compression for a particular java script file. How can I do that ?

  23. Thank you so much and its really solid ideas with very tricky but legal way. We just figured out few of our mistakes. Thanks again!

Leave a Reply

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