How to Enable GZIP Compression in WordPress

 

 

One of the first solutions to achieve faster load times of your WordPress CMS is to decrease the size of your page.The simplest method to reduce the size of your website, and improve the time to first render of your web pages, is to enable GZIP compression. Enabling GZIP compression on your server can significantly reduce the amount of time to download the requested resource. Today we will show you how to enable GZIP compression on WordPress.

How to Check if GZIP Compression is Enabled

If you want to check if the GZIP compression has already been enabled on your site, all you have to do is to go to free Check GZIP compression tool. This for sure is one of the easiest ways to check if the GZIP is enabled on your server, because you only need to write your website address and press the button.

How To Enable Gzip Compression For WordPress Websites

There are several different methods that you can use in order to enable GZIP compression on your WordPress website, so let’s dive into.

Enable GZIP on Apache

TO enable GZIP compression on Apache web server, you need to edit your .htaccess file. The following lines of code needs to be added to your .htaccess file. The .htaccess file can be found in the root or the WordPress site.

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

Enable GZIP with WordPress Plugin

You can use a caching plugin which supports GZIP compression, as one of the simplest ways. For example, the WP Rocket will add the rules of GZIP compression to your .htaccess file and it will automatically use mod_deflate. If you want to enable this through W3 Total Cache you need to go under it`s performing section and enable it.

Enable GZIP on NGINX

If you are running on NGINX, all you have to do is to add the following lines to your nginx.conf configuration 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;

Original Article