Vary
ResponseActiveThe Vary header tells caches which request headers affect the response content – instructing them to store separate cached versions for different values. Vary: Accept-Encoding is nearly universal (different compression for gzip vs brotli). Vary: Accept enables content negotiation caching. Incorrect Vary values cause cache poisoning or missed cache hits.
Vary: <header>[, <header>]*
Description
Vary lists the request headers that the server used to select the response. Caches use this to determine when a cached response can be used for subsequent requests. A cache must not serve a cached response if the listed headers differ from the original request. Vary: * effectively disables caching.
Directives
| Directive | Description |
|---|---|
| Accept-Encoding | Cache separately for gzip, br, zstd. Nearly all servers should include this. |
| Accept | Cache separately for different content types (JSON vs HTML). |
| Accept-Language | Cache separately per language. Increases cache storage significantly. |
| * | Any request would have its own unique cache entry. Effectively disables caching. |
Examples
Standard encoding vary
http
Vary: Accept-EncodingContent negotiation
http
Vary: Accept, Accept-Encoding