Best Way to Enable Gzip Compression on your WordPress Site

Join InfoPhilic Community!

Let's build a community to help & encourage each other to grow!

What is Gzip Compression?

Gzip is a file format and a software application used for file compression and decompression. Enabling Gzip Compression reduces file size by 60% to 80%, which helps server for faster network transfers.

Enabling gzip on your server increases page load speed of your website. Even, I myself use Gzip compression on my websites.

How to enable Gzip compression

You can enable Gzip compression using following methods:

  • Compression is enabled via .htaccess file on your server
  • By Using W3 Total cache

Enable compression via .htaccess

To enable compression via .htaccess file put the following code in your .htaccess file on your server.

For Apache web servers with mod_gzip

The code below should be added to your .htaccess file

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

You can also compress using DEFLATE mod. To do so, you have to add the following code in .htaccess file. Don’t know how to edit .htaccess file? Read about 3 correct ways to edit .htaccess file.

For Apache web servers with mod_deflate:

<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE "application/atom+xml" \
"application/javascript" \
"application/json" \
"application/ld+json" \
"application/manifest+json" \
"application/rdf+xml" \
"application/rss+xml" \
"application/schema+json" \
"application/vnd.geo+json" \
"application/" \
"application/x-font-ttf" \
"application/x-javascript" \
"application/x-web-app-manifest+json" \
"application/xhtml+xml" \
"application/xml" \
"font/eot" \
"font/opentype" \
"image/bmp" \
"image/svg+xml" \
"image/" \
"image/x-icon" \
"text/cache-manifest" \
"text/css" \
"text/html" \
"text/javascript" \
"text/plain" \
"text/vcard" \
"text/vnd.rim.location.xloc" \
"text/vtt" \
"text/x-component" \
"text/x-cross-domain-policy" \

You can use any one code of the above to enable compression on your server. Mod_gzip enables Gzip compression. Mod_deflate compress the output files from your server before it is being served to your visitor. Both has good results with the compression so you can use any one of them.

Enable compression on NGINX web servers

To enable compression in NGINX web server you will need to add the following code to your config file of your website

gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Disable for IE < 6 because there are some known problems
gzip_disable "MSIE [1-6].(?!.*SV1)";

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;

If you are using a W3 total cache plugin, you don’t need to add any code stuff in your .htaccess file. All you need to follow these steps:

  1. Go to WordPress dashboard
  2. Open Performance tab from the left navigation
  3. Under the Browser cache check for Enable HTTP (gzip) compression

This will reduce the download time of the text based files on your website.

Need help to configure W3 Total cache plugin for best results? Read:

Testing Compression

To check if te compression is working or not visit, input your website URL and check compression. That’s so easy 🙂


At the end of this tutorial, you must be learned to enable Gzip compression on your website. For apache web server users, I would recommend using mod_deflate in .htaccess file on the web server. This will also speed up your WordPress blog.

Also, test your WordPress blog speed using speed testing tools like Pingdom (online service to check website speed). Not satisfied with your website speed? Read our tutorial How to Make the WordPress Blog Faster.

Subscribe to our newsletter

To be updated with all the latest news, offers and special announcements.

Comment Policy: Your words are your own, so be nice and helpful if you can. Please, only use your real name and limit the amount of links submitted in your comment. We accept clean XHTML in comments, but don't overdo it please.


Please enter your comment!
Please enter your name here


Start WordPress Blog: Ultimate Guide For Beginners

Here is our step by step guide for beginners to start a WordPress blog.

Top 6 Best WordPress Theme Frameworks

There are many websites themes which are created by using a framework. Likewise, WordPress Theme frameworks also becoming so popular. The framework allows you...

The Most Essential WordPress Plugins

Here, I have listed some excellent plugins which will surely add more features and new functionality to your WordPress blog.

Tips to Speed Up WordPress Performance

Here, I am sharing some tips to speed up WordPress performance. All you need to modify .htaccess file on your server and add some plugins.

The Ultimate Guide to Harden WordPress Security

Learn how to improve WordPress security. Here are some basic security concepts that will help you to harden WordPress security.

How to Setup CloudFlare Free SSL for WordPress Blog

Google has announced that they will count HTTPS as a ranking factor which means if you using HTTPS you will get a higher position...


WP Coupons

The #1 WordPress coupon plugin for affiliate marketers to increase your CTR and conversions!


Get almost 100% PageSpeed on Newspaper theme

The newspaper theme is the most popular premium theme for a self-hosted WordPress blog. The theme is developed by team tagDiv. You...

How to Remove jQuery Migrate in WordPress?

jQuery Migrate greatly simplifies the process of moving older jQuery code to a higher jQuery version by identifying deprecated features. It then restores deprecated...

Tips to Speed Up WordPress Performance

Here, I am sharing some tips to speed up WordPress performance. All you need to modify .htaccess file on your server and add some plugins.

Guide to Set up Perfect WordPress SEO Permalink Structure

In this guide, I will tell you about how you can choose a perfect permalink structure for your blog to acquire good rankings in...

How to Fix Failed to Open Stream Error in WordPress

When WordPress.Org releases a new update to it’s WordPress standalone CMS (Content Management System) for that you may have set your website to get...

How to Disable Google AMP & Remove AMP Content from Google Search

Most of the users access the internet on their mobile phones. But, all the sites are not mobile friendly yet. Thus, Google started a...