Vary

Indicates to caching layers how to handle responses based on different request headers.

When a web browser sends a request to a server, it includes some "Request Headers" to tell the server what sort of response it would prefer. For example, it might include the following headers to indicate that it wants an English response and that it can use a variety of algorithms to compress the data.

Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

The server may respond with a English webpage compressed with the gzip algorithm. Or if this was a French website without any English content, then it may have sent back French even though English was requested.

The server needs a way to inform the web browser (and other caching layers) which "Request Headers" were used to vary the response. This is where the Vary header comes in, it tells the browser which headers were used. For example, this response tells the browser that it varied the response based on the Accept-Encoding and Accept-Language headers.

Vary: Accept-Encoding, Accept-Language

If the browser had sent different values for these headers in its request, then the server would have given a different response. This is important for caching purposes. If a cache stored and retrieved documents based only on the URL, then it may incorrectly cache an English page and serve it to a French user. Using the Vary header ensures that clients receive accurate and contextually relevant responses based on their request headers, even when caching is involved. It prevents the serving of incorrect content to clients.

Ready to validate your website to check for this header and 100+ others important tests?