gzip, used as a data compression tool, was developed by Jean-Loup Gailly and Mark Adler, who set out to build a strong alternative tocompress, the program written for Unix.
It is a technology defined in the POSIX standard that compresses files using the adaptive Lempel-Ziv algorithm for its functions and behavior. The team behind it did good work, and we should note that this is now the most widely used compression method. You can test your own site in the section below.
gzip technology saves up to 80% on your site.
Test GZIP on Your Site
Compression Test
See this value for your own site straight away: enter your address and your Compression Test result, plus insights specific to this tool, will appear here.
Free, no sign-up needed; the analysis also personalizes every one of our tools for your site.
How does gzip work?
gzip is short for ‘GNU ZIP‘, and it rests on the freely available deflate algorithm, a variant of the LZ77 data compression method (Lempel-Ziv 77), together with Huffman coding. Using those techniques, gzip scans files for repeated strings of data. When the program meets those repeated sequences it replaces them with a reference to the first occurrence. The length of these sequences is usually limited to 32,000 bytes. If a string does not appear in the previous 32,000 bytes, it is stored uncompressed in the gzip file, which takes the .gz ending. The procedure works on single files, so the packing program tar has to create so-called tarball archives with the .tar, .gz and .tgz endings. That is the technical side and the story of it. No need to stretch it further. Now we will go through how to enable it on your server and the settings you need on your site.
How to use gzip compression on your Apache web project
Web servers usually offer the practical compression process as a module you have to enable . These days many web hosting providers share this feature, though that was not the case in the past. The reason was probably that compression takes extra processor power. If you are not sure whether gzip is authorised by your server, you can contact your server administrator directly, or run a manual query instead. On an Apache web server, for example, check the server module settings with a simple phpinfo() output. The HTTP_ACCEPT_ENCODING information tells you which compression method was chosen.
If gzip is installed on your server, you have a few options for putting the compression helper to use.
Enabling gzip compression in the .htaccess file
To do it across your whole site (it applies to the current directory and all subdirectories) and to configure your web server in real time, you can add a piece of code to a .htaccess file. The .htaccess file usually sits in the root directory and lets the configuration file be read automatically on every request that reaches the site. With some web hosting providers, though, the .htaccess file is kept in a different folder, hidden, or closed to access. In that case your only option is to contact the host and ask for access. If you can make the configuration changes, add the code below to the .htaccess file to switch on gzip compression ( mod_gzip ) or the deflate algorithm ( mod_deflate ):
You can switch compression on for your site with a simple PHP command. There is one awkward problem, though: the code has to be entered separately in every PHP document. So you should only use this option on servers where you do not have the rights to edit the .htaccess file. The line of code to place at the top of each file is this:
<?php
ob_start("ob_gzhandler");
?>
Apply gzip through a WordPress plugin
On top of those two manual solutions there is an option that takes only minimal effort to set up: you can enable gzip compression using a plugin for the content management system you use. Plugins of this kind, which you can put in place within a few minutes and adapt to your needs, mainly help speed up sites on PHP-based systems such as WordPress. The list below holds the most popular plugins for your WordPress site:
W3 Total Cache : the WordPress plugin W3 Total Cache promises to raise website performance tenfold. Alongside various caching mechanisms and dedicated mobile support, this SEO and usability package also lets you make a great many settings, the option to enable gzip compression among them.
Check and Enable GZIP compression : also built for WordPress, the most common CMS, this plugin lets you check whether gzip compression is enabled for your project. If GZIP compression is off, the plugin helps you set it up.
If you use Joomla!, the compression function comes with your website out of the box.
How to enable gzip on your NGINX web server
When you deliver the content of your site to visitors through an NGINX web server, you can use gzip to improve the loading time of your project as well. To do that you only need to configure the ngx_http_gzip_module module. By default the ‘gzip’ directives used to enable or disable the compression service are off. To change that setting, open the nginx.conf file and search for the ‘gzip’ directive with CTRL + F. Then change ‘gzip off’ to ‘gzip on’. The table below shows the meaning and the possibilities of the other directives for configuring gzip compression in NGINX:
Directive
Syntax
Default setting
Description
gzip_buffers
gzip_buffers – number and size;
gzip_buffers 32 4k, 16 8k;
Sets the number and the size of the buffers used for compression
gzip_comp_level
gzip_comp_level – compression ratio;
gzip_comp_level 1;
Sets the compression ratio; possible values: 1–9
gzip_min_length
gzip_min_length – minimum length;
gzip_min_length 20;
Sets the minimum length of the response in bytes
gzip_http_version
gzip_http_version – version number;
gzip_http_version 1.1;
Sets the HTTP version a request must use to be answered with a compressed response
gzip_types
gzip_types – content type;
gzip_types text/html;
Sets which content types compression applies to (CSS, JSON, XML and others are also possible)
Differences between GZIP and its alternatives
In the table below we go through the advantages and disadvantages of the main alternatives to gzip.
Method
Advantages
Disadvantages
gzip
– Widely used and broadly compatible – Fast to compress and decompress – Reasonable compression ratio – Low memory use
– A lower compression ratio than some modern algorithms
bzip2
– A better compression ratio than gzip – Effective on large files
– Slower than gzip – More CPU and memory use
xz
– Very high compression ratio – Ideal for large files
– Slow to compress and decompress – High memory use
lzma
– A high compression ratio close to xz – Slightly faster than xz
– Still slower than gzip – High CPU use
zstd
– Fast to compress and decompress – Good compression ratio – Low memory use
– Not as effective as gzip on very large files
lz4
– Very fast to compress and decompress – Low CPU and memory use
– A lower compression ratio than the others
Test GZIP
To test gzip, enter your site address in the GZIP test tool section.
I began this work in 1999 and became an ODP editor in 2004. Today I provide SEO and Google Ads services to a great many large companies. I also chair Türk SEM Group and run the companies within it.