Caching · Response header
Vary
Which request headers cause different cached variants of the response.
What is Vary?
Vary tells caches that responses differ depending on the listed request headers — most commonly Accept-Encoding, Accept-Language, or Origin. Without a correct Vary, a CDN might serve a gzip-encoded response to a client that cannot decode it.
Typical usage
Set on any response that varies with request headers. Almost always include Accept-Encoding when compression is enabled.
Examples
Vary: Accept-Encoding, Accept-LanguageCommon gotchas
Adding too many headers to Vary destroys cache hit rate — each unique combination is a separate cache entry.
Specification
RFC 9110 §12.5.5
Related headers
Cache-Control
Directives that control caching behavior.
Accept-Encoding
Which content encodings (compressions) the client accepts.
ETag
A version identifier for the resource — the backbone of conditional GETs.
Expires
Legacy: an absolute HTTP date when the response becomes stale.
Age
How many seconds the response has been in a shared cache.