Skip to main content

Vary

ResponseActive

The 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

DirectiveDescription
Accept-EncodingCache separately for gzip, br, zstd. Nearly all servers should include this.
AcceptCache separately for different content types (JSON vs HTML).
Accept-LanguageCache 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-Encoding
Content negotiation
http
Vary: Accept, Accept-Encoding

Related

Specification

RFC 9110Vary specification →