Skip to content
RU
← All articles

Zstandard on the web: when to use it alongside Brotli

In short:

Offer zstd as an additional HTTP compression option when your server and clients negotiate it through Accept-Encoding, while preserving Brotli and gzip fallbacks. On three enterno.io files, zstd level 3 encoded faster than Brotli level 5 but produced larger output. The right choice depends on server load, caching and transfer cost.

Engineer reviewing transfer sizes in a server room
Compare compression speed with response size.

Zstandard is the compression algorithm defined in RFC 8878; HTTP uses the zstd coding token. Enabling it for a website is more than setting a codec flag. The client must advertise support, the server must select an acceptable representation, and intermediary caches must distinguish variants. We measured real HTML and JavaScript files from enterno.io to show the trade-off.

How HTTP negotiation works

GET /assets/app.js HTTP/2
Accept-Encoding: gzip, br, zstd

HTTP/2 200
Content-Encoding: zstd
Vary: Accept-Encoding

Accept-Encoding is a request header and Content-Encoding describes the returned body. If the client did not advertise zstd, do not send a zstd response. Vary: Accept-Encoding tells shared caches to key variants by this request header. Clients without zstd should receive an acceptable Brotli, gzip or uncompressed response. Compression belongs at the HTTP representation layer, while the underlying JS file keeps its usual media type.

Smaller output does not automatically make a request faster. A tiny response is often dominated by latency. A large script benefits from fewer transferred bytes. Dynamic HTML can make CPU time on every request the limiting factor. Precompressed static files are a different operational case from compressing every response at runtime.

Engineer comparing two network waterfall traces
Compare codecs on identical source files.

Results on HTML and two JavaScript files

We downloaded the public home-page HTML and two enterno.io JavaScript files. We compressed identical input bytes with gzip level 6, Brotli levels 5 and 11, and zstd levels 3 and 15. After warm-up, we used the median encoding time from 20 runs. The numbers describe one local CPU and these particular files, not a browser or network benchmark.

FileRaw sizegzip 6Brotli 5zstd 3Brotli 11zstd 15
HTML261,127 B48,240 B / 2.15 ms39,949 B / 2.58 ms46,280 B / 0.45 ms35,196 B / 228 ms39,488 B / 20.20 ms
app.js121,922 B33,182 B / 1.59 ms31,047 B / 1.64 ms35,212 B / 0.33 ms26,906 B / 114.79 ms29,555 B / 10.92 ms
vendor.js208,493 B70,705 B / 3.21 ms67,403 B / 3.44 ms73,083 B / 0.73 ms60,994 B / 232.41 ms64,363 B / 16.65 ms

For all three files, Brotli 5 was smaller than zstd 3, while zstd 3 encoded faster. Brotli 11 reduced bytes further but required much more encoding time. That can be reasonable when immutable assets are precompressed once. It does not justify compressing every dynamic response at the slowest setting. No codec wins for every file and workload.

Choose by workload

SituationUseful starting pointWhat to inspect
Cached static JS and CSSPrecompressed Brotli and gzip; test zstd tooSize and cache hit rate
Dynamic HTML under loadFast gzip, Brotli or zstd settingsCPU p95 and TTFB
Client without zstdBrotli or gzip fallbackCorrect representation
Very small responseCheck if compression helpsTransferred bytes

Already compressed WebP and AVIF images rarely gain much from an additional HTTP compression pass. Focus on text HTML, CSS, JavaScript and JSON. If a CDN recompresses origin responses, understand which layer chooses the final codec. A response must not be compressed twice.

Check your own server

Request the same URL with different Accept-Encoding values. Inspect Content-Encoding, Vary, status and actual body size. The enterno.io HTTP header tool can show response headers, while curl gives a repeatable local check.

curl -sSI -H 'Accept-Encoding: zstd, br, gzip' https://example.com/app.js
curl -sSI -H 'Accept-Encoding: gzip' https://example.com/app.js
curl -sSI -H 'Accept-Encoding: identity' https://example.com/app.js
# each Content-Encoding must match a supported client coding;
# Vary should include Accept-Encoding

Use GET to compare transferred bodies because some stacks handle HEAD differently. Record TTFB and total time with both cold and warm cache. Repeat on several representative files. If network phases dominate, the curl timing guide helps put byte savings in context.

Safe rollout

  1. Record your current gzip/Brotli behavior and cache configuration.
  2. Confirm the server or CDN actually supports zstd as an HTTP content coding. Do not infer native module support from a product name.
  3. Enable zstd for a small set of text URLs and test clients with and without support.
  4. Compare compressed size, CPU, TTFB and decoding errors under realistic traffic.
  5. Expand only where the measured trade-off helps, then follow field metrics and cache behavior.

When TTFB rises, check whether large dynamic responses are compressed for every request. When a client receives unreadable data, inspect the content coding and intermediary cache. When variants are mixed, inspect Vary and cache keys. Correct negotiation matters more than a small byte saving.

How we made this

In November 2026 we saved three public enterno.io files and compressed the same raw bytes locally. The method.py script and data.json are stored with the draft. The table reports medians after warm-up and 20 repetitions. This test excludes network delay, browser decoding, CDN behavior and a representative sample of websites. We checked HTTP semantics against RFCs and MDN.

Interpret size and time together

For our HTML, zstd 3 and Brotli 5 differed by 6,331 bytes, while encoding took roughly 0.45 versus 2.58 ms. If HTML is personalized and cannot be cached, the server pays this CPU cost for every response. If it is static, a build can compress it once and serve it repeatedly without runtime encoding. Transfer size may then matter more. Other HTML inputs and compression settings can change the trade-off.

For app.js, Brotli 11 reduced the file to 26,906 bytes and zstd 15 to 29,555 bytes, but both high settings took longer to encode than fast settings. A build pipeline can do that work once. Confirm the CDN serves the precompressed asset without recompressing it. Local codec time alone does not describe user response time after deployment.

For vendor.js, fast zstd 3 produced 73,083 bytes and Brotli 5 produced 67,403. The difference on the wire may matter on a slow connection, but it also depends on parallel requests. If the file is already in the browser cache, neither encoding is involved in a repeat load. Check cache misses and the share of new visitors before optimizing a rarely transferred asset.

Rollout checklist

TestExpected outcome
Client advertises zstdServer may serve zstd when available
Client advertises gzip onlyNo zstd body
Client requests identityUncompressed representation or an allowed server response
Repeat through CDNCoding matches each request
Postrelease checkErrors, TTFB and CPU stay within budget

Compare field LCP separately from local encoding time: one number cannot prove the other. The field-data guide explains why one synthetic run is insufficient. Use the launch monitoring checklist to track the release.

Verify cache variants

Request one URL as a zstd-capable client, as a gzip-only client, and as a client asking for an uncompressed representation. Repeat after the CDN cache is warm. If the cache ignores Accept-Encoding, one client may receive a body it cannot decode. That appears as a broken script rather than a small performance regression.

Interpret Content-Length carefully: streaming responses may omit it. Save the actual response body and check size, coding and successful decompression. For JavaScript, confirm that the page still runs. Some tools transparently decode responses and display the decoded size. Label exactly which size your report uses.

Precompressed variants must match the same source asset version. If a deployment updates JavaScript but retains an old .br or .zst file, browsers can receive different code. Verify the source hash and variant contents during the build. Dynamic HTML has no reusable artifact, so measure CPU under realistic request rates and watch overload. The CLS diagnostic guide can help separate a visual regression from the compression change.

For small responses, account for headers and transport separately. Our table records compressed body size only; it does not measure TLS, HTTP headers or packets. If savings are only a few hundred bytes, extra cache variation may cost more than saved traffic. Do not decide from one file. Add representative JSON responses, HTML from several templates and JavaScript of different sizes to your own sample.

Record raw size, codec level, encode and decode times, repetition count, CPU model and cache state. This makes a comparison reproducible after a library or CDN change. Label a local test as local: a compressor benchmark cannot measure a visitor's network delay.

If the benefit is real, document the rollout as a controlled experiment: record the traffic share, codec settings and observation period. Roll back if script load errors or response latency rise. After rollback, request every variant through the CDN again; an obsolete compressed body can remain cached longer than the server configuration.

FAQ

Should zstd replace Brotli?

There is no universal answer. Brotli 5 made our JS files smaller, whereas zstd 3 encoded faster. Keep fallbacks and test your workload.

Why was zstd 15 not the smallest?

Compression levels across codecs are not equivalent. Brotli 11 produced smaller files in this sample; other input data can differ.

Is Vary enough for caching?

The header declares the response dependency, but your CDN and application cache must actually store variants separately. Test multiple request headers.

Sources

Check your website right now

Check your site's speed →
More articles: Performance
Performance
Gzip vs Brotli: Web Compression Compared
16.03.2026 · 1 049 views
Performance
CDN Cache Invalidation: Strategies for Fresh Content
16.03.2026 · 906 views
Performance
Latency vs Throughput: Network Performance Metrics
16.03.2026 · 790 views
Performance
What Is a CDN: How It Works, Why You Need It and How to Check
11.03.2026 · 778 views