The HTML, style sheets and scripts of a web page are text, and text can be packed before it travels and unpacked by the browser on arrival. The page looks identical, but fewer bytes cross the network. MDN names two methods as the relevant ones today, gzip and Brotli, and the practical question is how they differ and what you can expect from each.

This guide explains how the browser and server agree on a method, compares the two formats using their specifications, and shows how to estimate the effect with the compression ratio calculator and the download time calculator. It quotes no savings percentages that a specification does not state.

How the browser and server agree on a method

The agreement is a short exchange of two headers. MDN calls this proactive content negotiation. The browser lists what it can unpack, the server picks one and labels its choice.

Step Who What happens
1 Browser Sends Accept-Encoding: br, gzip, a list of methods it can decode, in order of preference.
2 Server Picks one it supports and compresses the body of the response.
3 Server Replies with Content-Encoding: br to name the method, plus Vary: Accept-Encoding so caches keep one copy per method.
4 Browser Decompresses the body just before using it.

The HTTP specification (RFC 9110) describes the two headers. Content-Encoding states which codings were applied so the receiver knows how to decode, and it is used to compress data "without losing the identity of its underlying media type". Accept-Encoding can attach weights, as in the specification's example gzip;q=1.0, identity; q=0.5, *;q=0. If none of the listed methods is available, the server should send the response without any coding.

Only the body is compressed. MDN describes this as end-to-end compression: the server compresses the body and intermediate nodes leave it untouched. Request and response headers are not shrunk by this mechanism.

What gzip and Brotli are, side by side

Feature gzip Brotli
Header token gzip br, registered by RFC 7932
Specification RFC 1952, with the DEFLATE method in RFC 1951 RFC 7932
Method LZ77 repeat references plus Huffman codes LZ77 plus Huffman codes, with context modeling
Look-back window Up to 32K bytes (32,768) 1 KiB − 16 B up to 16 MiB − 16 B
Extras 10-byte header and 8-byte trailer with a CRC-32 and the original size A static dictionary built into the format, and a header that records the window size

The two formats are not interchangeable on the wire. The header token tells the browser which decoder to run, so a body compressed with one method but labeled with the other cannot be decoded.

The look-back window is how far back the compressor may search for a repeat. Brotli's largest window, 16,777,200 bytes, is about 512 times gzip's 32,768. A larger window costs memory, because RFC 7932 requires the decompressor to keep at least that much decoded data. The static dictionary lets Brotli point to words stored in the format itself, so a first occurrence in a file can still be shortened.

RFC 7932 states its goal as a ratio "comparable to the best currently available general-purpose compression methods, in particular, considerably better than the gzip program". That is a design aim, not a measurement of your files. Real results depend on the content, and this guide does not quote one.

What to expect, and what not to compress

The DEFLATE specification gives one figure for its own format: "English text usually compresses by a factor of 2.5 to 3". Scripts and style sheets are not English prose, so treat that as a rough input, not a promise. The Web Almanac adds that HTTP compression helps text-based files, while the benefits do not extend to media, where compression is part of the encoding.

Worked example. Example: a 600,000-byte text file sent over a 10 Mbps link, using the specification's factor of 2.5 as the assumed input.

  1. Compressed size: 600,000 ÷ 2.5 = 240,000 bytes. Ratio 2.5:1; space saved (1 − 240,000 ÷ 600,000) × 100 = 60%.
  2. Time before: 600,000 × 8 ÷ 10,000,000 = 0.48 s.
  3. Time after: 240,000 × 8 ÷ 10,000,000 = 0.192 s.
  4. At the specification's factor of 3, the file shrinks to 200,000 bytes and the time falls to 0.16 s.

The Web Almanac also cautions that compressed responses must be decompressed to their full size, so compression reduces the bytes that travel, not the size of what the browser ends up holding. The page weight guide separates transferred bytes from original size.

Compressing twice is the usual waste. MDN advises compressing all files except already-compressed ones such as images, audio and video, and warns that a second pass can be counterproductive. DEFLATE caps the damage: its worst-case expansion is 5 bytes per 32K block, a 0.015% increase for large inputs. Very small responses gain little, because the gzip framing alone adds 10 + 8 = 18 bytes. Example: a 100-byte response starts with 18% of its size in framing. The guide to files that will not compress explains why, and how DEFLATE works covers the method inside gzip.

Common mistakes

  • Compressing images, audio and video again. These formats already compress their data. A second pass adds time and can add bytes. Leave them out of HTTP compression.
  • Assuming Brotli is always smaller. The specification states a goal, not a guarantee for every file. Compress your own files with both methods and compare the sizes with the ratio calculator.
  • Quoting a savings figure from another site. A percentage depends on the content. Use the calculator with your measured sizes.
  • Leaving out the Vary header. MDN says the server must send Vary: Accept-Encoding so that caches can store the different versions of one resource. Omitting it leaves caches unable to tell them apart.
  • Confusing HTTP compression with ZIP files. HTTP compression is negotiated per response and undone by the browser. A ZIP archive is a stored file you open yourself. See how ZIP files work.

FAQ

Does the visitor need to turn anything on?

No. The browser sends its supported methods on its own, and the server chooses. MDN notes that modern browsers and servers both support it, so the work is in the server settings.

Is gzip or Brotli the better choice?

Neither wins for every file. gzip is described by MDN as the most common method, and Brotli's specification aims for a better ratio than gzip. A server can offer both and let Accept-Encoding decide per visitor.

How can I tell if a response was compressed?

Look at the response headers in your browser's developer tools. A Content-Encoding value of gzip or br means the body was compressed. If the header is missing, the body was sent as is.

Does compression change what the page shows?

No. Both formats are lossless, so the browser recovers the exact original bytes after decompressing.

Sources

  1. IETF, RFC 1952: GZIP file format specification version 4.3. Accessed November 6, 2026.
  2. IETF, RFC 1951: DEFLATE Compressed Data Format Specification version 1.3. Accessed November 6, 2026.
  3. IETF, RFC 7932: Brotli Compressed Data Format. Accessed November 6, 2026.
  4. IETF, RFC 9110: HTTP Semantics. Accessed November 6, 2026.
  5. MDN Web Docs, Compression in HTTP. Accessed November 6, 2026.
  6. HTTP Archive, The Web Almanac 2025, Part IV, Chapter 14: Page Weight. Accessed November 6, 2026.