Skip to content

Commit 6cef6ee

Browse files
committed
fix(website): _headers 兜底所有 SPA 路由不缓存 HTML,杜绝过期 HTML 引用旧资源
1 parent f3446f7 commit 6cef6ee

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

website/public/_headers

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# Cloudflare Pages 缓存头。public/ 下的文件会被复制到 dist 根,CF Pages 读取本文件。
22
#
3+
# 匹配规则:同一请求命中多条规则时,靠后的规则覆盖靠前的同名 header,
4+
# 所以先写兜底的 /*,再写更具体的 /assets/*。
5+
6+
# 兜底:SPA 的所有 HTML 路由(/、/sponsors、/en/... 等实际访问路径都不是 /index.html)
7+
# 一律不做边缘长缓存,否则新部署后用户会拿到引用旧资源的过期 HTML(2026-07-07 缓存
8+
# 污染事故的根源之一)。
9+
/*
10+
Cache-Control: public, max-age=0, must-revalidate
11+
312
# Vite 输出的 /assets/* 是内容哈希文件名(内容变 → 文件名变),可安全永久缓存。
413
# 默认 CF Browser Cache TTL 只给 4h,导致同一文件反复回源、缓存命中率低(触发 CF 的
514
# 「源流量超必需 / Smart Shield」提示)。设为 1 年 immutable 从根本上提高命中率、减少回源。
615
/assets/*
716
Cache-Control: public, max-age=31536000, immutable
8-
9-
# index.html 等入口保持可重验证,确保新部署能及时被用户拿到(不要长缓存 HTML)。
10-
/index.html
11-
Cache-Control: public, max-age=0, must-revalidate

0 commit comments

Comments
 (0)