Cloudflare announced support for the HTTP response header Vary within its Cache Rules feature across all of its plans, including Free, Pro, Business, and Enterprise. The addition gives website administrators greater control over how the network handles requests that may produce multiple representations of the same resource, such as differences in language, image format, content type, or compression method.
The origin server uses Vary to identify request headers that can affect the response, but the header does not indicate whether every textual difference between the values of those headers actually leads to a different response. As a result, the caching system may treat similar values as separate variants, fragmenting content into a large number of items with low reuse.
Three Ways to Handle Variance
Cloudflare provides one of three actions for each header named by the origin in Vary:
- normalize: Normalize values before selecting the stored variant. This is the recommended option for negotiation headers such as Accept, Accept-Language, and Accept-Encoding when many values map to a limited number of responses.
- passthrough: Use the raw value, including capitalization, spaces, ordering, and duplicate values, when the precise difference affects the response.
- bypass: Do not cache the response if the header named in Vary is personal or highly variable, such as Cookie or User-Agent.
Vary: * always causes caching to be bypassed, because any part of the request, including information outside the HTTP message such as the IP address, may affect the origin's selection of the response.
What Changes in Practice?
When normalization is used, requests that look different but prefer the same result can share the stored variant. Cloudflare reduces Accept, Accept-Language, and Accept-Encoding values to a standardized form, making the values lowercase and sorting them according to quality priority, with alphabetical ordering in the event of a tie. The administrator can also specify supported media types or languages, such as text/html and application/json or en, fr, and de.
However, this behavior may eliminate differences that the origin needs. Cloudflare notes that q=0 values or certain language exclusions may be lost during abbreviation, so passthrough should be used if the origin needs to see those exclusions exactly as sent by the client. Passing through raw values may also recreate the fragmentation problem; values such as compact,full and compact, full may produce different cache keys even if the origin treats them as equivalent.
Origin Responsibility and Update Limitations
The origin must return Vary consistently with every cacheable response that may differ according to request headers, including fallback responses and errors. If one response omits the appropriate header, Cloudflare may cache that response without the required isolation.
Changing Vary settings does not automatically delete existing content; old entries may remain until they expire or a purge operation is performed. Vary configuration also does not replace a custom cache key in every case: Cloudflare recommends using a custom key when a request property is a fixed part of the resource's identity, and using Vary when the origin declares, in its response, the fields that actually affect it.
Why Does This News Matter?
The update addresses a practical trade-off in CDN networks: ignoring Vary may send the wrong format or language to the client, while treating every value literally may reduce the cache hit rate and increase requests returning to the origin. According to the article, an analysis of more than 120 million responses from approximately 50,000 popular websites showed that nearly 3,000 websites use variance across four or more fields, with some using 10, 23, or 47 fields.
The benefit remains tied to the quality of the origin's definition of the representations it provides and to selecting the appropriate action for each header. The settings are available through the Cloudflare dashboard, the Rulesets API, or Terraform, with the need to test different values and monitor CF-Cache-Status after deployment.