fix(web/sw): shell 资源用 network-first,硬刷新一次即生效#110
Merged
Conversation
之前 sw.js 对 app.js / style.css / xiaof.* / src/* 这些 shell 资源用的 是 stale-while-revalidate:先吐 cache 里的旧版,后台再拉新版放进 cache, 意味着每次部署后用户第一次刷新看到的还是旧版,要再刷一次才能用上新版。 Scott 之前反馈「修了还是抖」就是因为浏览器 SW 还在用旧 app.js。 现在改成 network-first:每次请求都先走网络,只有网络真的失败(离线/ DNS 等)才 fallback 到 cache。视觉上跟之前一样在线快,离线也一样能 用 shell;但部署新版后硬刷新(Cmd+Shift+R)一次就生效,不需要 clear site data,也不需要刷两次。 顺便把 CACHE_VERSION 从 v1 bump 到 v2,强制清掉旧 cache。
🤖 bot-review (comment-only · phase 1)Diff: Red-line checks:
Phase 2: auto-approve + auto-merge fire only when red-lines are clean, author is internal, and no needs-human path is touched. Block with |
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.
问题
Scott 反馈「PR #106/#109 已 merge、服务器 serve 的文件也是新的,但浏览器里还是抖」。
排查发现:
web/sw.js对app.js/style.css/xiaof.*/src/*这些 shell 资源用的是 stale-while-revalidate——先吐 cache 里的旧版给页面,后台再异步拉新版放进 cache。意味着每次部署后用户第一次刷新看到的还是旧版,要再刷一次(或 clear site data)才能用上新版。修复
shell 资源改成 network-first:
v1bump 到v2,activate 时清掉旧 cache。验证
node --check web/sw.js通过。