What Is Gzip Compression?
Gzip compression allows you to make files smaller thus reducing the amount of time required to transfer a resource from the server to a browser. In today’s web environment, many browsers and servers both support gzip compression. Its ability to reduce file sizes by up to 70% provides a great incentive to make use of this compression method. To enable gzip compression is considered a high-priority recommendation by site speed test tools, as without it you are unnecessarily increasing your webpage’s load time.
How Does Gzip Compression Work?
Gzip compression works by searching for duplicate strings within a file and then replaces the second string with a pointer to the previous string. This helps greatly reduce the amount of actual text within a file as there is usually a significant amount of whitespace and duplicate text.
As for server-to-browser communication, gzip works in the following way.
- A browser which understands gzip makes a request for a file from the web server.
- The server receives the request and notices that the browser understands gzip therefore returns a gzipped version of the requested file.
- The browser receives the file, decompresses it, and is able to read the data.
In the case that the browser does not understand gzip, the server will simply send an uncompressed version of the file. This inability for old browsers to support gzip compression is why the vary header plays a vital role in delivering the proper content.
How to Enable Gzip Compression?
Depending on which web server you are using, the method to enable gzip will vary. The following describes both an Apache gzip configuration as well as an Nginx gzip configuration.
Apache Gzip Configuration
Nginx Gzip Configuration
For Nginx users, the following snippet can be added to the .conf file in order to enable Nginx gzip.
KeyCDN users also have the ability to enable gzip compression for cached files delivered from our edge servers to your website visitors. This option is enabled by default for all users and can be found by navigating to the advanced features section of your KeyCDN zone.
To check if your site is gzip compression enabled, there are a variety of tools which can be used. Site speed test tools such a gtmetrix.com will recommend you to enable gzip compression if it is not detected. Another option is to use a tool such as checkgzipcompression.com. This tool tells you if gzip is enabled as well as how many bytes were saved by compression the data.
Which Compression Algorithm is Coming Next?
Gzip has been the primary compression method for years, however there is now a new, emerging compression method called Brotli. This compression method is still in the process of acquiring support from various browsers, however shows great promise in the compression results it is able to achieve.
Compression Algorithm Comparison Src: gstatic.com
To check if your server or CDN supports Brotli, use our Brotli test tool.