Gzip compression in WordPress without a plugin [how-to]
Gijs Hovens, December 21, 2018
What is Gzip compression for WordPress?
First of all, Gzip compression is not specific for WordPress websites. Gzip is a method to compress files before a server sends them to a client (visitor). Smaller files equal faster downloads. The same method is used by your browser to decompress the files. Gzip compression can reduce file size up to 90%!
The web server does not store Gzipped versions of files (like you might do with .zip files on your computer) but compresses them when a file is requested by a client. The time this takes is so short that the benefits of faster downloading outweigh this disadvantage.
Gzip is supported by all major browsers.
Check if Gzip is enabled
You can check if Gzip is enabled in three different ways: using Google PageSpeed Insights, use an online check and checking your headers. If you see that Gzip is enabled, you can skip to Step 3: Check your file size savings.
Option A: PageSpeed Insights
Most people encounter their first mention of Gzip through a test with Google PageSpeed Insights. If you have Gzip enabled Google will state:
You have compression enabled. Learn more about enabling compression.”
If you don’t have Gzip enabled, Google will state:
Compressing resources with Gzip or deflate can reduce the number of bytes sent over the network.”
Followed by a list of assets and possible savings in file sizes by compressing them.
Option B: Use an online Gzip check
Even easier is using the website CheckGzipCompression. Just fill in your domain name and go! We don’t recommend using a WordPress plugin to check your Gzip status, this is the hard way and installing useless plugins is never a good idea.
Option C: Check your headers for Gzip compression
A harder but more comprehensive way is to use your browsers dev tools to check the headers. Look for the line called ‘content-encoding’ in the Response Header. If Gzip is enabled it will show ‘Gzip’ (duh).
This method will also allow you to easier inspect elements that are hosted with a CDN or assets from external sources (like tracking scripts, ads, etc.). If you go to the network tab and check the size column, you will see compressed file size in black and the original size in grey.
First of all, all good web hosting companies should have Gzip enabled by default. Strongly consider switching hosts if they do not, speed will probably be suffering from other server settings as well.
All forms of enabling Gzip require permission to modify some specific files. The WordPress plugins WP Rocket and W3TotalCache can enable Gzip for you by modifying these files under the hood. It depends on your server settings if they are able to do this. In short, you have two options to enable Gzip:
Option A: Find a host that has Gzip enabled by default.
Since we care for speed we have Gzip enable for all websites hosted at Savvii.
Option B: Change your server settings
We will list instructions for Apache and NGINX. At Savvii we use NGINX. When you are hosting at Savvii, Gzip is enabled by default and you can just sit back and check your savings.
Make sure you are able to edit the .htaccess file. Paste the following lines in your .htaccess files AFTER all other lines in your file. Also check if you have the module ‘mod_filter’ loaded, otherwise compression will not work and give a 500 server error instead. As you can see, these rules specifiy the file types where Gzip will be applied and make sure that you keep compatibility with some really old browsers.
For nginx it is even less work. Just paste the following lines in your nginx configuration file.
Same as with apache, you specify the file types where Gzip will be applied and you make sure that you don’t use Gzip for some really ancient browser versions.
Check your file size savings
After changing hosts or modifying your web server settings to use Gzip you should check your savings. The easiest way is to use the website CheckGzipCompression. This website will give you stats on the reduction in total file size.
For Savvii.com we achieved a reduction of 77% in file size by using Gzip.
Do you also want 15% more traffic through fast WordPress Hosting?
In our 112Brabant.nl and Brabantactueel customer case we explain how Savvii came to these results! Don’t you want that too?