Vary
Vary
The Vary
HyperText Transfer Protocol (HTTP) response header determines how to match future request headers. This information is required to decide whether or not a cached response can be served instead of requesting a fresh one from the origin server. This response header is used by the server to indicate the headers it used when selecting a representation of a resource in a content negotiation algorithm.
The Vary
header should be set on a 304
Not Modified
response exactly like it would have been set on an equivalent 200
OK
response.
Header type | Response header |
---|---|
Forbidden header name | no |
Syntax
Vary: * Vary: <header-name>, <header-name>, ...
Directives
- *
-
Each request for a URL is supposed to be treated as a unique and uncacheable request. A better way to indicate this is to use
Cache-Control
:no-store
, which is clearer to read and also signals that the object should never be stored. - <header-name>
-
A comma-separated list of header names to consider when deciding whether or not a cached response can be used.
Examples
Dynamic serving
When using the Vary: User-Agent
header, caching servers should consider the user agent when deciding whether or not to serve the page from cache. For example, if you are serving different content to mobile users, using this header can help you to avoid a cache mistakenly serving a desktop version of your site to your mobile users. This header can help Google and other search engines to discover the mobile version of a page and might also tell them that no Cloaking is intended.
Vary: User-Agent
Specifications
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
Vary |
Yes |
12 |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Compatibility notes
See also
- Understanding The Vary Header - Smashing Magazine
- Best Practices for Using the Vary Header – fastly.com
- Content negotiation
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary