HTTP headers | Vary
The HTTP Vary header is a response-type type header. It is used to indicate which headers it used when selecting a representation of a resource in a content negotiation algorithm and determines how to match future request headers to decide whether a cached response can be used rather than requesting a fresh one from the origin server. If you want to serve different content for the mobile users, then it can help to avoid that a cache may mistakenly serve a desktop version of your site to your mobile users. It will help search engines to discover the mobile version of a page.
Directives: There are two directives accepted by HTTP headers Vary.
- *: This wild card directive that will be used to match all future request headers to decide whether a cached response.
- <header-name>: This directive holds the header name, also can hold multiple headers, that will be used to match future request headers to decide whether a cached response.
To check this Vary in action go to Inspect Element -> Network check the response header for Vary like below, Vary is highlighted you can see.
Supported Browsers: The browsers compatible with HTTP headers Vary are listed below:
- Google Chrome
- Internet Explorer