Skip to the content
Start free

Text compression (Gzip and Brotli)

Text compression is when a web server shrinks text files such as HTML, CSS and JavaScript before sending them, and the browser unpacks them on arrival; Gzip and Brotli are the 2 formats almost every site uses. Nothing is lost on the way. The visitor gets the exact same file, just in fewer bytes, so pages arrive faster.

What is text compression? #

Text repeats itself. The same tags, words and code patterns appear again and again. A compression format replaces those repeats with short references. MDN’s guide to compression in HTTP calls this lossless compression: after packing and unpacking, the data matches the original byte for byte. The same guide says text can typically have as much as 60% redundancy, and that for some documents compression cuts size by up to 70%.

This is not the same as minification. Minifying removes spaces and comments from the file itself. Compression packs whatever file you have for the trip. Most sites do both.

Gzip and Brotli: what is the difference? #

Gzip Brotli
Specification RFC 1952, May 1996 RFC 7932, July 2016
How it packs The DEFLATE method, with a CRC-32 check for damaged data LZ77 and Huffman coding, plus context modelling and a built-in dictionary
Header value gzip br
Usual role The safe fallback every client understands The first choice where the browser supports it

Brotli was written by 2 engineers at Google. Its RFC says it gives efficiency comparable to the best general-purpose methods available at the time. A key trick is a static dictionary built into the format, so common words can be referenced without first appearing in the file. MDN’s Content-Encoding reference also lists zstd (Zstandard, RFC 8878) and newer dictionary-based variants, but Gzip and Brotli remain the 2 that matter for most sites.

How does it work? #

It is a short conversation in the HTTP headers:

  1. The browser asks for a file and says which formats it can read: Accept-Encoding: br, gzip.
  2. The server picks one, compresses the body and answers with Content-Encoding: br.
  3. The server adds Vary: Accept-Encoding, so any cache in between keeps separate copies for each format.
  4. The browser unpacks the file and uses it as normal.

MDN explains that the Vary header is a must here: without it, a CDN or edge cache could hand a Brotli file to a client that only reads Gzip.

Smaller files arrive sooner. That helps page speed and feeds the Core Web Vitals, especially Largest Contentful Paint, because the HTML and CSS that block the first paint get through faster. Google’s Lighthouse has long had an audit called Enable text compression. Its documentation says that in Lighthouse 13 the check moved into the Document request latency insight. Our page on Google Lighthouse explains where to find it in reports from PageSpeed Insights.

Why does it matter for AI answers? #

AI crawlers fetch pages too, often in large numbers. Every byte you save is saved on every one of those requests. Compressed responses mean less bandwidth spent on bots and less load on your origin server. Our guide on whether AI crawlers will slow your website covers the wider picture, and our AI crawler page explains who is visiting.

What does Lighthouse look for? #

Google’s audit page says Lighthouse gathers text-based responses that are not served with a content-encoding of br, gzip or deflate. It then compresses each with Gzip to estimate the saving. It skips files under 1.4 KiB, and files where the saving would be under 10% of the original size. Its advice: switch compression on at the server, prefer Brotli, and keep Gzip as a fallback.

Common mistakes #

  • Compressing images again. MDN advises compressing everything except already-compressed files such as images, audio and video. Packing a JPEG a second time can even make it bigger. Shrink pictures with formats like WebP and AVIF instead.
  • Forgetting the Vary header. Caches then mix up versions.
  • Only compressing HTML. CSS, JavaScript, JSON, SVG and XML files such as your XML sitemap are text too.
  • Testing without the request header. A test that does not send Accept-Encoding gets an uncompressed reply and wrongly concludes compression is off.
  • Turning compression off to “fix” a plugin. Find the clash instead. It is one of the common reasons a website is slow.

A worked example #

A small UK online shop’s product page sends a 240 KB HTML file, a 180 KB stylesheet and a 400 KB JavaScript bundle, all uncompressed. The owner switches on Brotli with Gzip as the fallback in the server settings. To check, she asks for the page from the command line:

curl -sI -H "Accept-Encoding: br, gzip" https://www.example.co.uk/product/

The reply now includes content-encoding: br and vary: Accept-Encoding. In Chrome DevTools, with large request rows on, the Size column shows 2 figures for each file: the bytes sent over the wire on top and the unpacked size below. The bytes on the wire drop sharply. The exact saving depends on the file, which is why she measures rather than guesses.

How do you check it? #

  1. Run any address through our HTTP header checker and look for content-encoding in the response. Our HTTP header checker guide walks through the results.
  2. Test the full page with our page speed checker or Core Web Vitals checker to see the effect on load time.
  3. Check cache behaviour with our cache checker, including the Vary header.
  4. Turn raw byte counts into plain sizes with our data size converter, and shrink scripts first with our JavaScript minifier.
  5. For a site-wide view, our asset diet report (Pro) is being built to list heavy files page by page.

Questions #

Should I use Gzip or Brotli? #

Both. Serve Brotli to clients that ask for it and Gzip to the rest. The browser’s request header decides.

Does compression change my content? #

No. It is lossless. The unpacked file is identical to the original.

Does it help time to first byte? #

Not directly. TTFB is about when the first byte leaves the server. Compression shortens the time to receive the rest.

Sources #

Updated 24 November 2026 by URSY.

Cite this page: Text compression (Gzip and Brotli). URSY. Updated 24 November 2026. https://ursy.com/wiki/text-compression-gzip-and-brotli/ · Section links

Tools for this

  • LiveImage SEO Checkeralt text, AVIF/WebP, sizes and licence markupRun the check →
  • LiveVerify an AI Botis it really GPTBot? IP, published lists and user agentRun the check →
  • Livellms.txt Checker + Generatorcheck your llms.txt, or write llms.txt, llms-full.txt and llms.jsonRun the check →
  • LiveAI Training Opt-Out Checker + Generatorwhat each AI may do with your site, and the exact lines to change itRun the check →
  • LiveAI Consistency Checkerpage, schema, llms.txt and feeds state the same facts?Run the check →
  • LiveGoogle Snippet Previewtitle and description length in pixels (in browser)Run the check →
  • ProAI competitor gapPrompts where rivals appear and you don'tIn URSY Pro →
  • ProAI fact accuracy monitorAI quoting your prices and facts wrong, with alertsIn URSY Pro →
  • ProBrand facts (Truth Spine)Your official facts, each with proof, for AI to readIn URSY Pro →

All 871 wiki entries, A to Z →