# Zstandard

> The Zstandard (zstd) is a fast lossless compression algorithm supported by browsers for HTTP responses.

## What is Zstandard (zstd) compression for HTTP?

The lossless compression algorithm that offers compression ratios close to Brotli with much faster compression speed. Served with the 'zstd' value of the `Content-Encoding` header and suits dynamically generated responses.

- Topic: Compression
- Type: technique

## Example

Wrong:

```http
HTTP/1.1 200 OK
Content-Type: text/html
Content-Encoding: zstd
```

Right:

```http
HTTP/1.1 200 OK
Content-Type: text/html
Content-Encoding: zstd
Vary: Accept-Encoding
```

`Vary` tells caches the body depends on `Accept-Encoding`, so a zstd response is not served to clients that cannot decode it.

## Common mistakes

- Serving zstd to every client, so browsers without support get unreadable data.

## Key points

- The server sends 'zstd' only when it appears in the request `Accept-Encoding`, with Brotli or Gzip as fallback.
- Responses include `Vary: Accept-Encoding` so caches do not mix encodings.

## Interview questions

### Zstd vs Brotli: which is better for the web?

Brotli usually gives slightly smaller static files. Zstd compresses much faster at similar ratios, which helps dynamic responses.

### What happens if a browser does not support zstd?

It does not list 'zstd' in `Accept-Encoding`, and the server should fall back to 'br' or 'gzip'.

### Can I precompress static files with zstd?

Yes. Compress at build time with a high level, for example `zstd -19`, and serve the file when the client accepts 'zstd'.

## Related cards

- [Brotli](https://wonderium.dev/web/brotli.md)
- [Gzip](https://wonderium.dev/web/gzip.md)
- [CDN](https://wonderium.dev/web/cdn.md)
- [HTTP Header](https://wonderium.dev/web/http-header.md)

---

- Level: [Web Platform](https://wonderium.dev/web.md)
- HTML version: https://wonderium.dev/web/zstd
- Last updated: 2026-11-25
