Skip to main content
sitewarm
HTTP caching headers

What does the Vary header do for caching?

Vary lists the request headers that changed the response. Caches store one variant per value, so a broad Vary splits the cache and lowers hits.

Vary is an HTTP response header that lists the request headers the origin used to choose the response, such as Accept-Encoding or Accept-Language. A cache may reuse a stored response only for later requests whose listed headers match the original ones, so each combination of values becomes its own cache entry.

Vary: Accept-Encoding

Vary: *

Vary: * means the response depends on something outside the request headers, so no stored response can be matched to a later request without asking the origin. In practice it disables reuse.

  • Each value adds variants. Vary: Accept-Language can mean dozens of copies of one page, each of which starts cold after a purge.
  • Variants are part of the effective cache key, and a broad Vary lowers the cache hit ratio.
  • CDNs limit it in their own ways. Vercel, for example, does not cache a response whose Vary names Cookie, and returns it with x-vercel-cache: MISS.

When you warm a cache, send the header values your visitors send, or the warmed variant is not the one they get.

References

  1. RFC 9110: HTTP Semanticshttps://www.rfc-editor.org/rfc/rfc9110
  2. MDN: Varyhttps://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Vary
  3. Vercel: CDN Cachehttps://vercel.com/docs/caching/cdn-cache

Warm your cache after every deploy

sitewarm requests the pages in your sitemap after a deploy and reports the cache state the CDN returns for each one, with the vantage point it was measured from.