Skip to content

fix(site): CSS/JS 内容 hash 版本号,根治边缘缓存样式不更新 - #66

Merged
jnMetaCode merged 1 commit into
mainfrom
fix/css-cache-busting
Jun 19, 2026
Merged

fix(site): CSS/JS 内容 hash 版本号,根治边缘缓存样式不更新#66
jnMetaCode merged 1 commit into
mainfrom
fix/css-cache-busting

Conversation

@jnMetaCode

Copy link
Copy Markdown
Owner

styles.css/app.js 加 ?v=<内容hash>,部署 CSS 改动后立即生效,绕过 Cloudflare max-age=86400 边缘缓存。

问题:styles.css/app.js 设了 max-age=86400,Cloudflare 边缘缓存旧版,
部署 CSS 改动后用户仍看到旧样式(详情页排版修复一度不可见)。

修复:HTML 引用改为 styles.css?v=<hash> / app.js?v=<hash>,hash 取文件
内容 sha256 前 10 位。内容变→URL 变→边缘按新 key 取新文件(立即生效);
内容不变→URL 不变→继续命中长缓存。HTML 本身 max-age=0 始终新鲜,
保证总是引用到最新版本号。

验证:重建 42 页,首页与详情页 CSS/JS 引用均带 ?v=hash。
@jnMetaCode
jnMetaCode merged commit f1b0cbe into main Jun 19, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant