Most of the time, gzip compression will make your server perform better and more resource efficient. This tutorial will show you how to enable gzip compression for your nginx server.

What is gzip compression

Gzip is a file format and a software application used for file compression and decompression.The program was created by Jean-loup Gailly and Mark Adler as a free software replacement for the. With some compression methods the last byte or code can be interpreted as more data if you try to read more data than was present when compressing, due to leftover bits, but I'm not sure this holds for gzip.

Gzip is a method of compressing files (making them smaller) for faster network transfers. It is also a file format but that’s out of the scope of this post.

Compression allows your web server to provide smaller file sizes which load faster for your website users.

Enabling gzip compression is a standard practice. If you are not using it for some reason, your webpages are likely slower than your competitors.

Enabling gzip also makes your website score better on Search Engines.

How compressed files work on the web

When a request is made by a browser for a page from your site, your webserver returns the smaller compressed file if the browser indicates that it understands the compression. All modern browsers understand and accept compressed files.

How to enable gzip on Apache web server

To enable compression in Apache, add the following code to your config file

How to enable gzip on your Nginx web server

To enable compression in Nginx, you will need to add the following code to your config file

As with most other directives, the directives that configure compression can be included in the http context or in a server or location configuration block.

The overall configuration of gzip compression might look like this.

How to enable gzip on your WordPress

If you have a WordPress website and you can’t edit the Apache or Nginx config file, you can still enable gzip using a plugin like WP Super Cache by Automattic.

After installing the plugin, go to its Advanced Settings tab and check on the settings “Compress pages so they’re served more quickly to visitors. (Recommended) to enable gzip compression.

However, keep in mind that this plugin comes with a lot of more features, some of which you may not want. So if you don’t like the extra features, you can just use a more simple plugin like Gzip Ninja Speed Compression or Check and Enable Gzip Compression.

How to check if gzip is successfully enabled and working

Gzip Compression Wix

Using Firefox to check gzip compression

Gzip Compression Checker

If you are using Firefox, do the following steps:

  • Open Developer Tools by one of these methods:
    • Menu > Developer > Toggle Tools
    • Ctrl + Shift + I
    • F12
  • Switch to Network Tab in the Developer Tools.
  • Launch the website that you want to check.
  • If gzip is working, the request to html, css, javascript and text files will have the Transferred column smaller than the Size column, where Transferred column displays the size of the compressed content that was transferred, and the Size column shows the size of the original content before compression.

Using Chrome to check gzip compression

If you are using Chrome, do the following:

  • Open Developer Tools by one of these methods:
    • Menu > More tools > Developer Tools
    • Ctrl + Shift + I
    • F12
  • Switch to Network Tab in the Developer Tools.
  • Launch the website that you want to check.
  • Click on the request you want to check (html, css, javascript or text files), the request detail will be displayed.
  • Toggle Response Headers of that request.
  • Check for Content-Encoding: gzip.
  • If gzip is working, the Content-Encoding: gzip will be there.
  • Make sure you check the Response Headers and not the Request Headers.

Frequently Asked Questions

How efficient is gzip?

As you can see in the Firefox Developer Tools Network Tab, the compressed size is normally one third or one fourth the original size. This ratio differs from requests to requests but usually that’s the ratio for html, css, javascript and text files.

Will gzip make my server slower?

OK, that’s a smart question. Since the server has to do the extra work to compress the response, it may need some more CPU power. However, the CPU power that is saved during transferring the response usually makes up for that, not to say that more CPU power is saved. Therefore, at the end of the day, normally your server would be more CPU efficient.

Should I enable gzip for image files (and media files in general)?

Image files are usually already compressed, so gzip compressing the image will not save you a lot of bytes (normally less than 5%), but on the other hand requires a lot of processing resource. Therefore, you shouldn’t enable gzip for your images and should only enable gzip for html, css, javascript and text files.

Disclosure: Hosting Canada is community-supported. We may earn a commission when you make a purchase through one of our links. Learn more.

Nginx Gzip Compression

Recent statistics suggest that more than 50 percent of online shoppers in the U.S. will abandon a purchase if the website that they are browsing on loads too slowly. Accordingly, it’s vital that you ensure the fastest possible load times.

Gzip compression wix link

Using the right Canadian web host helps, but there are other options. One of the quickest is to enable GZIP compression.

GZIP compression decreases the size of your webpages, which makes them faster to load. It’s supported by all web browsers, but it may not be enabled on your server.

Defining GZIP Compression

GZIP’s purpose is the compression of files. It’s a server-side product that reduces the size of JavaScript files, stylesheets and HTML. Some WordPress users have reported a reduction of 70 percent with GZIP compression. That’s impressive, and using GZIP is really easy.

Webmasters who haven’t enabled GZIP may see a warning when using GTmetrix or Google PageSpeed Insights for speed testing.

In Google, you’ll see a suggestion regarding how compression decreases the number of bytes sent and received.

Similarly, GTmetrix makes a recommendation to use GZIP compression to decrease the transfer size of files.

Is GZIP Compression Enabled on Your WordPress Website?

GZIP is commonly used, and it’s not rare for web hosts to make this capability part of their default package. Similarly, browser support for GZIP is widespread, with some browsers having had this capability for nearly 20 years. Popular browsers such as Safari, Internet Explorer, Chrome, Opera and Firefox all are prepared for GZIP compression.

If you’re not certain that your web host provides GZIP compatibility, then you’ll want to check. Moreover, it’s worth taking some steps to ensure that GZIP compression is enabled on your WordPress website.

How to Check for GZIP Compression

Two straightforward methods are available if you want to check on whether or not GZIP is enabled on your website. The first of these involves checking the GZIP Compression tool.

All you have to do is visit this site. Input your URL in the search box, then click “Check.” Within seconds, you’ll know whether or not your website is GZIP enabled. If so, it will tell you how much faster your website performed because of the compression. If not, it will return an error.

Another option is checking Google Page Speed Insights.

Gzip Compression Ratio For Text

Keep in mind the GZIP compression also may be applied to static assets. Websites that serve assets via a CDN will want to check that these are enabled for GZIP as well. You can use the same tool to check GZIP readiness.

The other way to check whether or not your website is GZIP enabled is by verifying that the HTTP response header “content-encoding: gzip” is active.

For instance, Chrome users can open Chrome Devtools and review the first response header in the “Network” section. If the entry says “content-encoding: gzip,” then you don’t need to do anything.

Alternatively, click on the “View Large Requests” button, and you’ll see both the original and compressed page sizes. If a compressed page size isn’t displayed, then GZIP may not be enabled.

Enabling GZIP Compression

GZIP compression may be enabled via a WordPress plugin. Caching plugins are the ones that are most commonly used for this. Some of the more popular plugins for this purpose include WP Rocket and W3 Total Cache.

If you are on a shared host that uses Apache, then you have the option of modifying your .htaccess file. Before beginning, ensure that mod_filter is loaded on your server. If not, then you will receive an error. Then, insert this code in your .htaccess file:

Gzip Compression Algorithm

Webmasters running Nginx will add this code to their nginx.conf file:

Ensuring that GZIP is enabled on your WordPress website is one of the quickest and easiest ways to improve visitor experience. With the potential to reduce the size of your website by 70 percent, you have no reason not to ensure that compression is enabled. Your website visitors will certainly thank you for it, and you’re bound to see an increase in sales as well.

Too Hard? Try These Options

Gzip Compression Test

  1. Ask your host to set you up. Companies like BlueHost or SiteGround will get their tech support to get this going for you.
  2. Use WP Rocket which has a gZip option.
  3. Watch the video below