HTTP Vary Header Reference

HTTP Vary header usage with CDN caching implications and common field names.

Reference for HTTP Vary header semantics covering Accept-Encoding, Accept, Cookie and Origin usage, cache-key fragmentation risks and CDN normalisation guidance.

What does the Vary header do?

Vary lists the request headers a cache must include in its cache key. If a response says Vary: Accept-Encoding, the cache stores a separate entry for each distinct Accept-Encoding value, so a gzip client never receives an identity-encoded body and vice versa.

The header that decides what your cache stores

Vary is the single most misunderstood caching header. It tells every cache — the browser, a CDN, a reverse proxy — which request headers must be part of the cache key. Get it right and content negotiation works through caches; get it wrong and you either serve the wrong variant or shred your hit rate. This reference rates the common Vary field names by safety and cache impact.

How it works

When a response includes Vary, a cache stores one entry per distinct combination of the listed request-header values:

Vary: Accept-Encoding, Accept-Language

A request only matches a stored entry if its values for those headers match. So varying on Accept-Encoding keeps gzip and Brotli bodies separate (correct), while varying on Cookie or User-Agent fragments the cache into near-unique entries (harmful). CDNs often normalise values — collapsing dozens of Accept-Encoding strings down to gzip/br/identity — to keep the key small.

Tips and pitfalls

  • Always Vary: Accept-Encoding for compressed responses.
  • Avoid Vary: Cookie and Vary: User-Agent on cacheable assets — they bust caches.
  • Vary: Origin is needed for CORS responses cached across origins.
  • Vary: * makes a response uncacheable by shared caches — use sparingly.
  • Keep the list minimal; every extra field multiplies the number of stored variants.