---
title: "Compress every text response · Agent Wranglers"
url: https://agentwranglers.se/playbook/website/performance/compression
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Compress every text response

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Performance](https://agentwranglers.se/playbook/website/performance.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- ID: WEB-46
- Level: Recommended
- Chapter: [Performance](https://agentwranglers.se/playbook/website/performance)
- Rule: Compress every text response with Brotli (or zstd), with gzip as a fallback, ideally ahead of time at the highest level.
- How: Compress static text files at build time (Brotli 11 and gzip 9) and serve the right one by `Accept-Encoding`. Compress each rendered page once and keep the result. Compress the rest on the fly at a moderate level. Name the encoding header as [Say which request headers change a response](https://agentwranglers.se/playbook/website/performance/vary) says.
- Check: `curl -sI -H 'Accept-Encoding: br'` shows `Content-Encoding: br` for HTML, CSS and JS. With `Accept-Encoding: gzip` the same files come back as `gzip`.
- Measured: On a reference site, turning compression off took Lighthouse mobile Performance from 99 to 92 (from 99 to 89 on a second page). It took LCP from 2.1 to 3.3 s (from 2.1 to 3.75 s on the second page). It took page weight from 202 to 403 KB. On those two pages, it was the largest single effect of every feature tested.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Shell example

```sh
# at build time
brotli -q 11 -k dist/*.html dist/*.css dist/*.js
gzip -9 -k dist/*.html dist/*.css dist/*.js
```

### nginx example

```nginx
brotli_static on;   # needs the ngx_brotli module
gzip_static on;
gzip on;
gzip_comp_level 5;
gzip_types text/css application/javascript application/json image/svg+xml text/markdown;   # text/html is always on
```

## Sources

- [RFC 9110 – Accept-Encoding](https://www.rfc-editor.org/rfc/rfc9110#field.accept-encoding)
- [RFC 7932 – Brotli Compressed Data Format](https://www.rfc-editor.org/rfc/rfc7932)
- [RFC 8878 – Zstandard Compression](https://www.rfc-editor.org/rfc/rfc8878)

## Related rules

- [Say which request headers change a response](https://agentwranglers.se/playbook/website/performance/vary) in Website
- [Use shared dictionaries for big bundles](https://agentwranglers.se/playbook/website/performance/compression-dictionary-transport) in Website
- [Send more in the first round trip](https://agentwranglers.se/playbook/website/hosting-and-network/tcp-initial-congestion-window) in Website

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/website/performance/compression">Agent Wranglers website playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Ignore tracking parameters in caches](https://agentwranglers.se/playbook/website/performance/no-vary-search)
- Next: [Load fonts without moving the page](https://agentwranglers.se/playbook/website/performance/font-loading)
- [Performance](https://agentwranglers.se/playbook/website/performance)
