DEV Community

On notifio.app brotli beats gzip on 9 pages and loses on 29, and the dividing line is about 60 KB of HTML

A sibling site of mine has a post saying its CDN compresses with brotli quality 3 and plain gzip wins on 20 of 79 pages. notifio.app is served from Vercel's edge, as the x-vercel-cache header on every response says, so I expected the same story and wanted the Notifio numbers, mostly because I did not know where the line between the two encodings fell.

The measurement

For each of the 38 URLs in the sitemap I made three requests with curl, setting only Accept-Encoding to identity, gzip and br, and recorded the bytes that came down the wire. Then I fetched the identity body once more and compressed it locally with brotli at qualities 0 to 5, 9 and 11 and with gzip at levels 1, 6 and 9, to see which setting the edge was using.

  • identity 2,123,636 100.0%
  • gzip, as served 400,535 18.9%
  • brotli, as served 400,322 18.9%

Two hundred and thirteen bytes apart over 38 pages. Brotli is supposed to be the better format. On this site, as served, it is a tie.

Which setting the edge is using

Local brotli totals, for the same 38 bodies:

  • quality 2 413,368
  • quality 3 400,250 <- served: 400,322
  • quality 4 379,535
  • quality 5 352,266
  • quality 11 311,033

Quality 3 matches the served bytes to within 72 bytes in total, and page by page it is within two per cent on all 38. No other quality is anywhere close on any page.

So the answer for Notifio is the same as for the sibling site: the edge compresses brotli at quality 3, which is a fast setting meant for compressing on the fly, not a good one. Gzip was served within 1.4 per cent of a local level 6.

Where gzip wins

This is the part the sibling post did not give me, because I had not looked for a pattern. Sorting the 38 pages by uncompressed size:

  • Brotli is smaller on 9 pages. The smallest of them is 60,164 bytes of HTML and the largest is the home page at 92,196.
  • Gzip is smaller on the other 29. The largest of those is 60,887 bytes.

So the crossover is about 60 KB, with a band between 60,164 and 60,887 where both win (/alerts and /for/expats go to brotli, /for/amsterdam, /alerts/rightmove and the scams guide go to gzip). Every page below 60 KB is smaller as gzip. Every page above 61 KB is smaller as brotli.

The five competitor pages under /compare are all in the brotli group, and so are the home page and the /alerts hub. The two smallest pages are the ones that lose worst on a percentage basis: /pricing is 6,294 bytes as brotli and 5,978 as gzip, and /download is 7,064 against 6,636. They are also two of the three no-store pages, which the edge cannot serve from its cache.

A quality 3 brotli stream has a fixed cost in header and block structure that a short document cannot amortise, which is my guess at why the line falls where it does. I did not test that mechanism, only the outcome.

What it costs

Both sides of the ledger are small, and nearly the same size: if every page used its smaller encoding:

  • 29 gzip pages would save 9,022 bytes over brotli
  • 9 brotli pages already save 9,235 bytes over gzip

A browser that sends Accept-Encoding: br, gzip is given brotli on every page, so it pays the 9,022 bytes on 29 pages: about 311 bytes a page. The most any single page loses is 432 bytes. Nobody will feel that.

The more interesting number is what a better brotli setting would do. At quality 11 the 38 pages total 311,033 bytes, which is 89,289 less than served and 22 per cent smaller. That is about 2,350 bytes a page, with a worst page of 3,166. It is a real figure and still a modest one: a few kilobytes on pages that are already under 15 KB on the wire. It would matter more if the HTML were the heavy part of a visit, and on our pages it is not.

What I did not check

The Vary header on all 38 pages lists four of Next.js's own request headers (rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch) and not Accept-Encoding. A sibling post probed what that means for a cached page. I did not repeat the nine-value probe here, so I make no claim about odd Accept-Encoding values on Notifio.

The cache state was 35 HIT and 3 MISS, the three being the no-store pages, and I measured the HIT bodies from one location at one time. It is also one machine's view of one edge.

I cannot set the brotli quality on this host from our side, so there is nothing to change in the repository. The finding is the shape of the thing: on a site of short pages, the encoding that sounds better is better only on the longest quarter of them, and the line is easy to find if you sort by size.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.