Vary is an HTTP response header that names the request headers a server used to choose its response. A cache must store and match separate versions based on the values of those headers.
Why it matters
Without Vary, a cache can serve the wrong variant. The classic case is compression: if one client gets gzip and another cannot handle it, a cache that ignores the difference may deliver compressed bytes to a client that cannot read them. Used badly, though, it fragments the cache and lowers the cache hit ratio.
Example
HTTP/1.1 200 OK
Content-Encoding: br
Vary: Accept-Encoding
Cache-Control: public, max-age=3600
The cache now keeps separate entries for Accept-Encoding: br, gzip, and none. Other legitimate uses are Vary: Accept-Language and Vary: Accept for content negotiation.
Vary: Cookie or Vary: User-Agent makes nearly every request unique. A CDN will then hold thousands of near-identical copies and rarely serve a hit. You can see what your site sends with the HTTP header checker.
Common mistakes
- Varying on
User-AgentorCookiefor pages that do not truly differ. - Omitting
Vary: Accept-Encodingon compressed responses. - Using
Vary: *, which effectively disables shared caching.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.