fix: 修复 SPA 入口被缓存导致部署后仍加载旧前端 - #6
Merged
Merged
Conversation
index.html is returned for every unmatched route and carries no content hash, but the static handler set no Cache-Control at all. Browsers therefore applied heuristic freshness and intermediaries such as Cloudflare cached it by extension, pinning clients to whatever bundle existed at cache time. Redeploys appeared to do nothing, which is what made the new account-page UI (for example the API key delete button) keep showing an older build. - index.html and other unhashed files: no-cache, must-revalidate - Vite's content-hashed assets: public, max-age=31536000, immutable Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
index.html会被所有未匹配路由返回,且文件名不带内容哈希,但静态处理完全没有设置Cache-Control:浏览器因此走启发式缓存,Cloudflare 等中间层也会按扩展名缓存
.html。结果是重新部署后客户端仍加载旧 bundle——这正是账号页新 UI(例如删除 API Key 按钮)始终不出现的直接原因。修复
index.html及其他无哈希文件:Cache-Control: no-cache, must-revalidateCache-Control: public, max-age=31536000, immutable(内容变则文件名变,可安全长缓存)验证
新增
TestStaticServingSetsCacheHeadersForSPAEntryPoint、TestIsImmutableBuildAsset;go test ./...全绿。