Book a call Free rebuild

Gzip

August 12, 2022 Updated November 16, 2026 2 min read

Performance glossaryGzip is a lossless compression format servers use to shrink text files such as HTML, CSS, and JavaScript before sending them, so they download faster.

Gzip is the long-standing standard for compressing web content in transit. The server compresses a text response, such as an HTML page, a stylesheet, or a JavaScript file, and the browser decompresses it on arrival. Text compresses well because it is full of repetition (think how often <div class= appears in a page of HTML), so the files that travel over the network are a fraction of their original size.

The gzip program appeared in 1992 as a free replacement for the Unix compress tool, and its file format is defined in RFC 1952. It is a lossless format: the decompressed file is identical to the original.

How it works

  1. The browser lists the formats it accepts in a request header, for example Accept-Encoding: gzip, deflate, br.
  2. The server, or a CDN in front of it, compresses the response and labels it Content-Encoding: gzip.
  3. The browser decompresses the response and uses it as normal.

Underneath, gzip uses the DEFLATE algorithm, which combines LZ77 (replacing repeated strings with references to earlier copies) and Huffman coding (giving common symbols shorter codes).

Compression levels

Gzip has levels from 1 (fastest) to 9 (smallest). Higher levels cost more CPU for gains that shrink quickly, so servers compressing pages on the fly typically use a middle level. Static files can be compressed once at the highest level and stored, so that cost is paid only once.

What to compress, and what not to

Compress text: HTML, CSS, JavaScript, JSON, XML, SVG, and plain text. Do not gzip JPEG, PNG, WebP, or AVIF images, video, WOFF2 fonts, or ZIP files. They are already compressed, so gzip wastes CPU and can even make them slightly larger.

Gzip vs Brotli

Brotli, a newer format, usually makes text files smaller than gzip does, and every modern browser supports it over HTTPS. Most servers and CDNs now send Brotli when the browser accepts it and gzip otherwise. Gzip remains the universal fallback, supported by practically every HTTP client.

Enabling gzip on a WordPress site

Compression is a server setting, not a WordPress one. Most hosts and every major CDN enable it by default. On a self-managed server, Apache uses mod_deflate and nginx the gzip on; directive, each with a list of content types to compress. Some caching plugins add the Apache rules to .htaccess automatically.

How to check it is working

In the browser's developer tools, open the Network tab, reload, and select the HTML document. The content-encoding response header should read gzip or br. If it is missing, the page was sent uncompressed, which PageSpeed Insights flags in its "Document request latency" insight.

WP Services

WordPress services at revolutionary pricing.

Productized WordPress services, from builds to care, delivered by Seahawk and tracked in one app. For the WordPress lovers.