Vary

Adds the specified request headers to the cache key for the resource.

Fastly reads this header from responses. It is defined by an external standard.

A Vary response header tells caches that a particular header (or headers) from the request should be used to make the cache key for the object more specific. The specified request headers, when received in future requests, must match the values recorded on the request that triggered this response, in order to use the cached response to answer the subsequent request.

A common use case is Vary: Accept-Language, which allows a server to produce versions of the same webpage in different languages and serve them to browsers based on their local language settings. The presence of the Vary header on the response ensures that a user whose preferred language is English will not be served a page that was previously fetched (for the same URL) as a result of a request from a user whose preferred language was Chinese.

Vary is an HTTP standard, and Fastly supports it per spec, but since this is one of the most popular ways to apply complex logic to the Fastly cache, we have produced a lot of content on proper usage of this header. See the following blog posts for details: