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

Specification
Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content (HTTP/1.1)
# header.vary

Browser compatibility

BCD tables only load in the browser

Compatibility notes

See also