It is very simple to enable gzip compression in WordPress. If you are looking to free up some bandwidth and lower your transfer volume to your visitors, you will definitely want to use gzip.

There are two main methods to enabling gzip, either through the use of a plugin, or by editing your website’s .htaccess file. Many popular caching plugins like W3 Total Cache and WP Super Cache have options to enable gzip compression. For example, the image above is an example of the gzip compression setting in WP Super Cache.

Enable Gzip Through .htaccess (Apache)

If your web server runs Apache, place the below code in your .htaccess file:

#Gzip Compression#
<IfModule mod_deflate.c>
  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
</IfModule>
#End Gzip Compression#

Enable Gzip For Nginx

If your web server uses Nginx, enabling gzip requires you to enable to module. You will need sudo and edit this file:

sudo vim /etc/nginx/nginx.conf

In this file you will see that the gzip settings are commented out. You will need to uncomment the gzip settings and adjust them to your desired result.

Save the nginx.conf file, and then reboot the Nginx service with the below command:

sudo service nginx restart