InfoQ

Cloudflare Adds Configurable HTTP Vary Header Support to Prevent Cache Thrashing

8.5内容质量
Cloudflare Adds Configurable HTTP Vary Header Support to Prevent Cache Thrashing

TL;DR · AI 摘要

Cloudflare新增可配置HTTP Vary头支持,有效防止缓存碎片化,提升边缘网络效率。

核心要点

  • Cloudflare通过normalise/pass through/bypass三种策略处理Vary头,减少缓存碎片化
  • 审计显示3000个源站使用4个以上请求头作为Vary参数,导致缓存效率下降
  • 分阶段处理机制平衡了缓存正确性与边缘网络性能需求

结构提纲

按章节快速跳转。

  1. Cloudflare推出HTTP Vary头配置功能以解决缓存碎片化问题。

  2. Vary头指示缓存依据哪些请求头生成响应变体。

  3. 12000万响应审计显示3000个源站使用多请求头导致缓存效率下降。

  4. 源站指定影响因素,Cloudflare通过规则控制头处理方式。

  5. normalise标准化头字段,pass through保留精确值,bypass跳过缓存。

思维导图

用一张图看清主题之间的关系。

查看大纲文本(无障碍 / 无 JS 友好)
  • Cloudflare HTTP Vary头配置优化
    • 问题分析
      • 缓存碎片化成因
      • 审计数据统计
    • 解决方案
      • 双阶段处理机制
      • 三种配置策略
    • 技术实现
      • Cache Rules配置
      • 头字段标准化

金句 / Highlights

值得收藏与分享的关键句。

  • 审计发现近3000个源站使用4个以上请求头作为Vary参数,极端案例涉及数十个字段

    — 第3段

    ⬇︎ 下载 PNG𝕏 分享到 X
  • normalise策略可将Accept-Language等复杂头标准化为等效类,消除客户端差异影响

    — 第5段

    ⬇︎ 下载 PNG𝕏 分享到 X
  • bypass策略可跳过高基数或易变头的缓存,防止非确定性变体消耗缓存资源

    — 第5段

    ⬇︎ 下载 PNG𝕏 分享到 X
#Cloudflare#HTTP Vary#缓存优化#边缘网络#CDN
打开原文

Cloudflare Adds Configurable HTTP Vary Header Support to Prevent Cache Thrashing - InfoQ

InfoQ Homepage News Cloudflare Adds Configurable HTTP Vary Header Support to Prevent Cache Thrashing

Development

InfoQ Certified AI-Assisted Engineering Program (online, Oct 19): Build the harness that holds.

Cloudflare Adds Configurable HTTP Vary Header Support to Prevent Cache Thrashing

Sep 29, 2026 3 min read

by

  • Olimpiu Pop

#### Follow us on

Youtube

232K Followers

Linkedin

26K Followers

Instagram

New

RSS

19K Readers

X

57.1k Followers

Facebook

21K Likes

Bluesky

Listen to this article -

0:00

Audio ready to play

Your browser does not support the audio element.

Normal

1.25x

1.5x

Like

new dropdown rading list

  • Reading list

Cloudflare has released native support for the HTTP Vary response header across its global edge network, making the capability available within Cache Rules on all customer plans. The enhancement enables origin servers to negotiate representations such as localised text, modern image encodings, or alternate payloads while providing platform operators with fine-grained controls to prevent severe cache fragmentation.

Historically, intermediary content delivery networks have treated the HTTP Vary header with caution. Under standard HTTP semantics, the Vary response header indicates to downstream caches that an origin server evaluated specific request headers before generating a response. If a cache respects Vary without transformation, slight syntactic differences in client headers, such as variations in whitespace, casing, or client-preferred language priority orderings, can splinter a single resource into dozens of distinct variants. In an empirical audit of over 120 million HTTP responses across approximately 50,000 top domains, Cloudflare discovered that nearly 3,000 origins varied on four or more request headers, with extreme cases varying across dozens of distinct fields.

Uncontrolled header variance frequently causes cache thrashing, where hit ratios collapse and origin load escalates. To mitigate this tension between correctness and edge caching efficiency, Cloudflare decoupled the negotiation process into two operational stages. The origin server continues to specify which request headers influence response generation, while Cloudflare Cache Rules dictate how the edge processes, normalizes, or ignores the values of those headers before computing the variant key.

When configuring Vary handling within Cache Rules, operators can define behaviours per header or apply fallback policies across unlisted fields. The engine exposes three distinct actions: normalise, pass through, and bypass. Normalisation canonicalises complex negotiation headers like Accept and Accept-Language into standardised, equivalent classes, eliminating incidental client differences. Pass through stores exact, case-sensitive strings, which is necessary when origin applications depend on precise token matches. Bypass skips edge caching entirely for requests matching volatile or high-cardinality headers, ensuring non-deterministic variants never consume edge cache capacity.

An origin server serving multi-representation endpoints can advertise its dynamic dependencies using standard headers:

code
HTTP/1.1 200 OK

Content-Type: application/json

Cache-Control: public, max-age=3600

Vary: Accept, Accept-Language

Engineers configure Cloudflare to match these requests and manage header variability using the Cloudflare Ruleset Engine or the dashboard. The following JSON configuration illustrates a Cache Rule specifying normalization for content negotiation while routing unknown variants to pass through:

code
{
    "expression": "(http.request.uri.path eq \"/api/catalog\")",
    "action": "set_cache_settings",
    "action_parameters": {
        "cache": true,
        "vary": {
            "headers": [
                {
                    "name": "accept",
                    "action": "normalize"
                },
                {
                    "name": "accept-language",
                    "action": "normalize"
                }
            ],
            "default_action": "pass_through"
        }
    }
}

Under the hood, Cloudflare records the Vary fields announced by the origin alongside the base cache key, which consists of the scheme, host, and path. Subsequent incoming requests execute the base key lookup first. If variants are registered for that key, the edge extracts the corresponding request headers, evaluates them against the designated Cache Rule actions, and serves the matching variant. If no cached variant matches the normalised criteria, the request is forwarded to the origin, and the resulting payload is indexed into the variant pool.

Product manager Alex Krivit and systems engineer Zaidoon Abd Al Hadi highlighted that this two-step architecture resolves longstanding limitations of manual workarounds. Previously, teams had to choose between disabling caching, relying on specialised Cloudflare Workers, maintaining brittle custom cache keys that anticipated headers before seeing the origin response, or using specialised extensions like Vary for Images . Custom cache keys evaluate rules upfront on incoming requests, meaning they apply even when an origin returns static, invariant responses. By contrast, Vary rules in Cache Rules trigger dynamically only when the origin includes a Vary header, avoiding needless key space expansion for unvarying responses.

While the new mechanism reduces implementation friction for content negotiation, operators must evaluate cache key cardinality before enabling full pass-through modes on high-entropy headers. When headers containing arbitrary tokens or session identifiers are passed through, each distinct client string creates an isolated edge entry, reducing cache lifetime and increasing cache eviction churn. Vary support in Cache Rules is currently active for all Free, Pro, Business, and Enterprise zones.

main wrapper for authors section

About the Author

section title

main wrapper for each author

#### Olimpiu Pop

Show more

Show less

#### This content is in the Cloudflare topic

##### Related Topics:

  • Development
  • HTTP
  • Cloudflare
  • Related Editorial
  • Related Sponsors
  • Related Sponsor October 8, 2026, 12 PM EDT When AI Accelerates Development, Can Your CI Pipeline Keep Up? Presented by: Eric Metaj - Product Marketing Manager, Software Delivery at Datadog, and Rohin Chandra - Product Manager, CI/CD Optimization at Datadog

The InfoQ Newsletter

A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example

We protect your privacy.