日本語

How Much Brotli vs gzip Changes Core Web Vitals LCP

​​Core Web Vitals​Brotli,Chrome,gzip,Node.js,web-vitals

Switching the HTML from gzip to Brotli changed the Core Web Vitals LCP (Largest Contentful Paint) by a few tens of milliseconds on the page I tested. On a connection throttled to 1.6Mbps with a 150ms round-trip time, the median LCP was 272ms with gzip (level 6) and 216ms with Brotli (quality 5). At 10Mbps there was no meaningful difference.

This is useful if you are deciding whether to enable Brotli in your server or CDN compression settings. The largest LCP change came not from choosing gzip or Brotli, but from compressing Brotli at quality 11 on every request. That compression alone took about 0.4 seconds, and on every connection speed the LCP was slower than with no compression.

Note

The test environment was Ubuntu 24.04 (4 CPUs), Node.js 22.23.5 (zlib 1.3.1, Brotli 1.1.0), web-vitals 6.2.3, Playwright 1.63.0, and Chrome for Testing 158 (headless). The server was written with Node.js's https module, and the client connected over HTTP/1.1 within the same VM. The connection speed and latency were reproduced by delaying the server's response start and by pacing the body writes (I did not delay the TLS handshake round trips). I measured only one HTML page that loads no external files, with the median of 7 runs per condition. I did not test nginx or CDN configuration, HTTP/2 or HTTP/3, zstd, compression of CSS or JavaScript, or real smartphones.

The page and the compressed sizes

The test page is HTML with inline CSS in <head> (about 60KB), a heading and a lead paragraph at the top of the body, 400 product cards below that, and finally the same data as JSON. It is 233,411 bytes in total, and the LCP element was the lead paragraph (#lead) in every run.

I compressed it with node:zlib. The sizes and times (median of 20 runs) were as follows.

Compression Size (bytes) Ratio to original Compression time
None 233,411 100% —
gzip level 6 21,520 9.2% 2.28ms
gzip level 9 20,397 8.7% 5.23ms
Brotli quality 4 23,084 9.9% 1.40ms
Brotli quality 5 18,878 8.1% 2.47ms
Brotli quality 9 17,309 7.4% 13.21ms
Brotli quality 11 15,254 6.5% 364.11ms

Brotli quality 11 is 6,266 bytes smaller than gzip level 6, but it takes more than 100 times as long to compress. This page is made of repeated card markup and compresses well, so every method shrank it to around 10% or less.

Measuring LCP for each compression method

The server returned the HTML in one of five ways, depending on the URL. The compression time was returned in the Server-Timing header and read on the browser side.

  • No compression
  • gzip level 6 (compressed on every request)
  • Brotli quality 5 (compressed on every request)
  • Brotli quality 11 (compressed on every request)
  • Brotli quality 11 (compressed once at server startup)

There were three connection conditions: unthrottled, 10Mbps with a 40ms round-trip time, and 1.6Mbps with a 150ms round-trip time. I set the 1.6Mbps / 150ms condition close to Lighthouse's default mobile throttling (Slow 4G, 150ms round-trip time, 1,638.4Kbps). Chrome was launched with a new profile every time, and LCP was recorded with the attribution build of web-vitals. The Accept-Encoding sent by Chrome was gzip, deflate, br, zstd.

A horizontal bar chart for each connection condition showing the median LCP for the five compression methods. Only Brotli quality 11 compressed on every request stands out, at 536–644ms on every connection.
LCP median (7 runs) by HTML compression method and connection
Compression 1.6Mbps, 150ms RTT 10Mbps, 40ms RTT Unthrottled
None 480ms 128ms 176ms
gzip level 6 272ms 204ms 172ms
Brotli quality 5 216ms 212ms 200ms
Brotli quality 11 (precompressed) 240ms 220ms 176ms
Brotli quality 11 (compressed every request) 644ms 612ms 536ms

At 1.6Mbps, Brotli was tens of milliseconds faster

At 1.6Mbps with a 150ms RTT, the median time until the whole HTML was received was 266ms for gzip, 252ms for Brotli quality 5, and 229ms for precompressed Brotli quality 11. The smaller the compressed data, the sooner it arrived.

The median LCP was 272ms for gzip and 216ms for Brotli quality 5, a difference of 56ms. However, the 7 runs ranged from 240 to 292ms for gzip and from 212 to 288ms for Brotli quality 5, so the ranges overlap. Precompressed Brotli quality 11 (240ms) was slower than quality 5, but that also falls within this variation. On this page, the LCP reduction from switching to Brotli was on the order of tens of milliseconds.

On the 10Mbps connection and on the unthrottled connection, the gzip and Brotli difference was 4–28ms, and neither was clearly faster. The gzip and Brotli difference is only a few KB, so on a fast connection the arrival time barely changes.

web.dev's LCP article gives a target of 2.5 seconds or less (75th percentile). Compared with that, the time saved by switching from gzip to Brotli was small.

Brotli quality 11 compressed on every request is slower than no compression

When Brotli quality 11 was compressed on every request, LCP was the longest on every connection. At 1.6Mbps it was 644ms, which was 164ms slower than the 480ms with no compression and 372ms slower than gzip.

The cause is the time to first byte (TTFB). At 1.6Mbps, the median TTFB was 162ms for gzip and 523ms for Brotli quality 11 compressed on every request. The compression time reported in Server-Timing ranged from 320 to 624ms across 21 runs. In the measurement logs, br11 is per-request Brotli quality 11, br11pre is precompressed quality 11, and slow is the 1.6Mbps connection.

text
br11 slow: LCP median 644ms (min 592, max 700) TTFB median 523ms htmlResponseEnd median 593ms runs=7
br11pre slow: LCP median 240ms (min 228, max 324) TTFB median 159ms htmlResponseEnd median 229ms runs=7

Quality 11 precompressed once at server startup was 240ms. The size is the same 15,254 bytes, so most of the difference comes from waiting for compression (TTFB rose from 159ms to 523ms).

In the test environment, I also checked the default quality that zlib.brotliCompressSync() uses when no quality is specified, and how long this page takes to compress.

text
BROTLI_DEFAULT_QUALITY=11 BROTLI_MAX_QUALITY=11
brotliCompressSync(html)(オプションなし): 15254 bytes, 413.9ms
Warning

If you compress with Brotli on every request in Node.js, either lower the quality with zlib.constants.BROTLI_PARAM_QUALITY or cache the compressed result. If you don't specify a quality, you get quality 11, which is the slowest.

The Node.js zlib documentation also recommends caching compressed results because compression is CPU-intensive. In this test, Brotli quality 5 took about the same time as gzip level 6 and produced smaller output than gzip.

At 10Mbps, no compression had the shortest LCP

At 10Mbps with a 40ms RTT, LCP with no compression was 128ms, shorter than gzip (204ms). The uncompressed HTML finished arriving 233ms later, so LCP was recorded while the HTML was still arriving.

Looking at the breakdown of LCP, the time from the first byte of HTML until the lead paragraph was painted (elementRenderDelay in web-vitals; since the LCP element is text, this equals LCP minus TTFB) was 75–122ms with no compression and 136–168ms with gzip. Without compression the HTML trickled in, and Chrome painted the beginning first. In 4 of the 7 runs, the number of product cards in the DOM when the first LCP candidate was reported was 334–379, short of the full 400.

On the other hand, with gzip, Brotli quality 5, and precompressed quality 11, the HTML had fully arrived in the 60ms range, and the first paint happened after all 400 cards had loaded. With the connection unthrottled, the uncompressed HTML also finished arriving in about 10ms, so apart from per-request Brotli quality 11, every method clustered around 170–200ms.

However, at 1.6Mbps, LCP with no compression was 480ms, 208ms slower than gzip. Sending the 60,264 bytes up to the lead paragraph (most of it the CSS in <head>) over 1.6Mbps takes about 300ms. This result does not mean compression should be turned off on fast connections. It means that on a page like this, where a large HTML document follows the part that is painted first, compression does not always shorten LCP by the full amount of the size reduction.

​Posted by 86