How to Enable GZIP Compression in WordPress

WordPress

We know that the load time of a website now affects SERP. As per Google, if your website takes more than 2 seconds, you are losing valuable traffic. There are lots of things that affect load time. I already wrote how to speed up the WordPress website. Enabling Gzip compression is also a way to improve load time. If you are not sure how to enable Gzip compression in WordPress, keep reading. In this article, I will explain everything you need to know about Gzip and the way to enable it in WordPress.

What is GZIP Compression?

GZIP is a file format used for file compression. If it is enabled on the server side, it serves the compressed form of HTML, stylesheets, and Javascript files. Gzip compression can reduce files by up to 70%. When a user requests a web page, the browser checks if the web server has GZIP enabled by checking the content-encoding: gzip” response header. If this header is present, it serves compressed files.

Best Managed WordPress Hosting

WPEngine is the best and most secure managed hosting provider

Some web hosts such as Bluehost automatically enable GZIP compression on all new WordPress sites.

How to enable Gzip compression

Compression is enabled via web server configuration. So, different web servers have different steps to enable compression. WordPress has nothing to do with the server as it is just a PHP-based script. But caching plugins allow you to edit .htaccess rules to enable the GZIP compression.

In Apache server

If you know how to edit .htaccess file using Cpanel or FTP, you should add this code in .htaccess file. Add this code after the existing code. You can find this file at the root of your WordPress installation. Make sure to have a backup of this file before you make changes. If you do anything wrong, it will break your website.

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>

In NGINX

If you are running on NGINX server, add the following code in nginx.conf file.

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_types text/plain text/css text/javascript image/svg+xml image/x-icon application/javascript application/x-javascript;

Enable GZip compression using the WordPress plugin

Most good cache WordPress plugins offer an option to enable Gzip compression. For example, if you are using Wp Fastest Cache, this is where you can enable the Gzip compression. Just check this checkbox.

Wp Fastest Cache Gzip compression WordPress

Other cache plugins such as WP Super Cache, W3 Total Cache, and WP Rocket also have similar options in the configuration section. Just check the settings panel of the cache plugin you use.

How to check if Gzip Compression Is Working

There are a few websites where you can check if Gzip compression is working on your website. You can use these websites.

Final Words

There are several factors that affect the Website’s load time and every single thing should be taken care of. Gzip is an important thing and you must enable it on your website. You will surely see improvements in load time. The website’s load time affects its ranking on Google. So, you should take this seriously.

Do you want to say anything? Any thoughts or additional tips? You can leave a comment.


Deepanker Verma is an experienced WordPress developer who has been working on WordPress for more than 12 years. On TheWPGuides, he writes about WordPress, WordPress development, and WordPress plugins.


Similar Articles

0 Comments

Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

© 2022 The WP Guides Developed By Deepanker