Vary tells caches which request fields select a response variant. Correct variation prevents reuse of the wrong language, encoding, or origin-specific response.
Match the request as well as the URL
Vary: Accept-Encoding, OriginBefore reusing the stored response, an HTTP cache must account for the named request fields. A compressed representation and an uncompressed one may belong to different variants even at the same URL.
Vary does not grant cache permission, set a lifetime, or replace authentication. Cache-Control still determines storage and freshness.
Dynamic CORS needs variation
If an allowed request origin changes Access-Control-Allow-Origin, include Vary: Origin. Otherwise a shared cache may reuse a response with the wrong permission value.
Keep the variation consistent on relevant responses, including validation responses. Merge required field names instead of accidentally replacing Accept-Encoding when adding Origin.
Avoid unnecessary variants
Vary only on fields that genuinely affect selection. Highly variable fields can create many entries and reduce cache efficiency. Vary: * prevents ordinary reuse of a stored response without contacting the origin.
Cookie-based personalization deserves a deliberate private or no-store policy; Vary: Cookie alone is a poor default privacy boundary. CDNs can also have configured cache keys that need separate review. Test requests with different values rather than inspecting only one response.