What is Gzip Compression
Gzip is a file format and software application used on Unix and Unix-like systems to compress HTTP content before it’s served to a client. The process has been known to shrink a file by up to 80 percent, resulting in improved page load time, decreased bandwidth consumption and reduced SSL overhead (due to a decrease in the number of roundtrips during a SSL handshake).
File types associated with gzip include:
- .gz – Indicates a file extension compressed by the gzip algorithm.
- .tar file, tarball – A format used to store multiple files for archiving, but not for compression. Gzip can be used to compress .tar files.
- .tgz, .tar.gz, .gz file – Indicates a .tar file that’s been compressed by gzip.
Enabling the Gzip Command
Gzip can be applied to a number of different platforms, including those detailed below:
You can enable gzip on WordPress by using a caching plugin that supports gzip, or by enabling gzip on your web server via the .htaccess file.
To enable gzip on an Apache web server, add the gzip compression commands inside the
mod_deflate module at the end of the .htaccess file.
To enable gzip on NGINX, the following code must be added to the nginx.conf file:
Verifying Gzip Activation
After enabling gzip, the next step is to verify that it’s compressing your outbound files. This is done either by using any number of online tools, or by checking HTTP response headers in a browser, e.g., by making sure that in the Network > Headers tab in Google Chrome, Gzip is displayed under the Content-Encoding header.
Additionally, it’s possible to check HTTP response headers using cURL, by entering in the following command:
curl -H "Accept-Encoding: gzip" -I https://sitename.com
In the response, gzip should be listed in the Content-Encoding header:
HTTP/1.1 200 OK Server: nginx Date: Mon, 21 Jul 2014 01:12:36 GMT Content-Type: text/html; charset=UTF-8… Vary: Accept-Encoding Content-Encoding: gzip
Using Gzip in Conjunction with a CDN
Almost all content delivery networks (CDNs) provide automated file compression with gzip. This relieves you of the need to verify that compression is indeed taking place.
Additionally, CDNs typically support a number of front-end optimization techniques that can be used in conjunction with gzip to further shrink outgoing file size.
While minification before gzipping a file might seem redundant, it’s been shown to shrink tarfile size by an additional 5-10%. Because CDNs perform both minification and gzip compression, they minimize the size of the code files delivered to your users, significantly reducing page load time.