What is the Vary HTTP header

The HTTP Vary response header lists all of the client request headers that the server considers to select the document or generate custom content.

For example if the server response depends on the User-Agent header, the Vary must include User-Agent. Ex. Lets say if your server side code can generate a version of document that does not use JavaScript for browsers that do not support JavaScript then you should add Vary: User-Agent header.

The Vary header is used by the caching proxies (Proxy could be your corporate proxy, ISP proxy, or some other proxy). Big portion of internet traffic goes through one or other proxy. The caching proxies store the response generated by server and when they get the next request for same resource, from either same client or different client they can return response from the cache instead of going to the originating server.

When a new request arrives the cache find the matching document. Before it can serve this document to the client it must see whether the server sent a Vary header in the cached response. If a Vary header is present, the header values for the header in the new request must match the header values in the old, cached request. Because server may vary their response based on the client request headers, caches must store both the client request headers and the corresponding server response headers witch each cached variant.