剪报:Cache-Control 常见组合与 no-cache 的字面误区
每隔一段时间就会有人把 Cache-Control: no-cache 和 no-store 记混。把 Jake Archibald 那篇经典文章里的两套黄金组合再抄一遍:
"no-cache" doesn't mean "don't cache", it means it must check (revalidate via If-None-Match / ETag) with the server before using the cached resource. "no-store" means don't keep a copy at all.
# 1. 文件名带内容哈希的静态资源(app.8f3d1a.js):放心永久缓存
Cache-Control: public, max-age=31536000, immutable
# 2. HTML 入口页(index.html):允许存副本,但每次打开先发条件请求对一下 ETag
Cache-Control: no-cache
# 3. 展示略旧一点也没关系的资讯列表:1 分钟内直接用,过期后后台异步刷新
Cache-Control: public, max-age=60, stale-while-revalidate=600
只要入口 HTML 不被错误设成长 max-age,发版后最多一次 304 Not Modified 往返就能切到新哈希资源,既省流量又不会卡旧版。