Skip to content
hostcomplex

Gzip Compression

Maarten Soetens 2 min read

How Gzip Compresses Web Files

Gzip compression is a method that reduces the size of a file by encoding its repeated patterns more efficiently, and it is the most widely used form of HTTP compression on the web. The server compresses a response before sending it, and the browser decompresses it on arrival. The visitor sees the same content, only faster to transfer.

Gzip uses the DEFLATE algorithm, which works in two steps. It replaces repeated sequences of text with short references to an earlier copy, then it assigns shorter codes to the most common symbols. Text such as HTML and CSS contains many repeats, so it shrinks a lot. A file with little repetition gains much less.

The negotiation happens in HTTP headers. The browser announces what it understands with a request header such as Accept-Encoding: gzip, deflate, br. If the server supports gzip, it answers with Content-Encoding: gzip, which tells the browser to decompress the body. Shrinking code first with minification gives gzip a smaller input to work on.

Which Files Benefit From Gzip and Which Do Not

Gzip works best on text-based formats, which usually shrink by a large share:

  • HTML, including server-rendered pages
  • CSS and JavaScript files
  • JSON data returned by APIs
  • SVG images and other XML-based files

Some formats are already compressed and gain little or nothing. Examples include JPEG, PNG, WebP, AVIF, MP4 video and ZIP archives. Compressing them again wastes server time and can even make them slightly larger.

Because the response depends on the Accept-Encoding header, caches must store compressed and uncompressed versions separately. Servers signal this with a Vary: Accept-Encoding header.

Gzip on a Small Business Site

A bakery's website has an HTML page of about 180 KB, mostly repetitive navigation markup and text, plus a 90 KB stylesheet. Without compression, both files travel in full on every visit. With gzip enabled, the server sends much smaller versions of these text files, while the photos of the bread are sent unchanged.

The gain comes from the text, not the images. That is why compression is a quick win for text-heavy pages and a smaller one for photo-heavy pages.

Frequently asked questions

Is Gzip Compression Enabled by Default on Web Servers?

Not always. Whether gzip is active depends on the web server, the hosting platform and its configuration. Many hosts enable it, but the reliable way to know is to check the response headers of a page for a Content-Encoding line.

Is Gzip Better Than Brotli?

Neither is better in every case. Brotli usually compresses text more tightly than gzip, but it can be slower to compress on the fly. Gzip is supported everywhere and remains a reliable choice. Many servers offer both and pick based on the browser's request. The detailed comparison is in the Brotli vs gzip article.

  • Two-Factor Authentication

    Two factor authentication hosting adds a second check to control panel, domain and CMS logins. Learn which methods are strongest and why 2FA helps.

  • What Is an A Record?

    What is an A record? Learn how this DNS record maps a hostname to an IPv4 address, why domains use several A records and the root and www pattern.

  • Billing and Automation Platforms

    What is WHMCS? Learn how this commercial billing and automation platform helps hosts sell plans, collect payments and create accounts automatically.