AI-generated editorial illustration; not a documentary photograph.
Cloudflare has added support for the HTTP Vary response header to Cache Rules, giving customers controls for how request-header differences affect cached responses. The feature is available through the dashboard, Rulesets API and Terraform on Free, Pro, Business and Enterprise plans.
Why Vary causes cache fragmentation
Vary allows one URL to serve different valid representations, such as HTML or JSON based on Accept, or language-specific content based on Accept-Language. Without it, a cache can return the wrong representation. But comparing raw header values can also create many separate cache entries for requests that ultimately receive identical content, lowering reuse and increasing requests to the origin.
Three ways to handle variation
Cloudflare’s Cache Rules separate the origin’s declaration from the cache’s policy. An origin identifies headers that may change a response with Vary, while the rule can normalize configured values, pass exact values through, or bypass caching for a header whose values are too personal or unpredictable. Vary: * continues to bypass caching because any aspect of the request may affect the response.
Normalization is designed to group equivalent requests. For Accept, Accept-Language and Accept-Encoding, Cloudflare describes processing that lowercases values and orders them by quality, with optional limits on supported media types and languages. The normalized values are forwarded to the origin in the cases Cloudflare specifies, keeping origin selection aligned with cache matching.
What operators must account for
The origin still has to return Vary consistently for cacheable responses, including errors and fallbacks. A response that omits the necessary header could be cached without the variation needed to isolate it. Cloudflare also warns that changing a Vary configuration does not automatically purge existing content; old entries remain until expiry or an explicit purge, while requests may refill under new keys.
Vary versus custom cache keys
Cloudflare positions Vary for cases where the origin conditionally declares which request fields matter. A custom cache key remains more suitable when a request property always defines the resource, because it applies its configured dimensions to every covered response. Cloudflare advises avoiding duplicate treatment of the same header unless the behavior is deliberate and tested.
Source: We just shipped support for the ugliest part of HTTP: Vary

Leave a Reply