跳到正文
原文
Simon Willison·· 21 天前AI 评分20

Cloudflare 终于支持 HTTP 中最丑陋的 Vary 头

We just shipped support for the ugliest part of HTTP: Vary

AI 导读

Cloudflare 已支持 HTTP 的 Vary 响应头。此前 Cloudflare 缓存会忽略图片以外资源的 Vary 头,开发者按 accept: text/html 分发 HTML 或 JSON 时,可能把 JSON 版本缓存后返回给期待 HTML 的用户。Simon Willison 表示自己更倾向于用 .json 后缀让 URL 可预测地返回 HTML 或 JSON。

正文

23rd September 2026

I've been wanting this from Cloudflare for years.

The classic problem here is if you do that thing where user agents that send "accept: text/html" get HTML, while user agents that don't get JSON or some other format.

This used to be impossible to deploy behind Cloudflare caching, because they ignored the Vary header on anything other than images - so you risked caching the JSON version and then serving it up to someone who was expecting HTML.

(Independent of the Cloudflare feature I ended up deciding never to use that pattern, because I prefer having URL that predictably returns HTML or JSON - I add a .json suffix to my apps to serve JSON instead.)

来源:Simon Willison · simonwillison.net