back-forward-cache
它能做什么
这项技能检查页面中是否有阻止浏览器为即时前进和后退而保存页面的代码。适合希望访客在网站内快速返回页面的开发者。
适用场景
- ✓当访客点击返回后,页面加载很慢时。
- ✓当页面使用了 unload 监听器,或总是会执行的 beforeunload 提示时。
- ✓当页面恢复后,需要刷新具有时效性的数据时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/back-forward-cache/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请检查我的结账页面,看看有没有阻止返回导航即时完成的内容。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会查找 unload 监听器和无条件的 beforeunload 处理程序,把相关逻辑移到 pagehide 和 pageshow 中,并只刷新必须更新的数据。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Optimize pages for back/forward cache
Back/forward cache turns many browser back and forward navigations into near-instant restores because the entire page is resumed from memory instead of being rebuilt from the network. Losing bfcache eligibility makes common navigations feel far slower than they need to.
Quick Reference
- Never add an
unloadlistener - it is the most common bfcache blocker - Use
pagehideandpageshowinstead of assuming every navigation reloads - Refresh time-sensitive state when
pageshow.persistedistrue - Keep
beforeunloadconditional and remove it when there are no unsaved changes - Verify eligibility in DevTools instead of assuming a page is cacheable
Check
Review this route for back/forward cache blockers. Search for unload or unconditional beforeunload listeners, state that assumes every navigation is a full reload, and resource lifecycles that break when the page is resumed from memory.
Fix
Replace unload logic with pagehide and pageshow handlers, remove unnecessary blockers, and refresh only the time-sensitive state that must change after a bfcache restore.
Explain
Explain how the back/forward cache differs from HTTP caching, why unload blocks it, and how pageshow/pagehide should be used instead.
Code Review
Review route code, global listeners, analytics hooks, and data-refresh logic related to Optimize pages for back/forward cache. Flag exact listeners, APIs, or lifecycle assumptions that prevent a restore or leave stale state after a restore.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/performance/back-forward-cache
常见问题
什么是前进后退缓存?
这项技能把它描述为将整个页面保留在内存中,以便快速恢复,而不必重新从网络构建页面。
最常见的阻碍是什么?
这项技能说明,unload 监听器是最常见的阻碍因素。
怎样确认页面符合条件?
这项技能建议在浏览器开发者工具中进行验证。
详情
作者的原始描述
Use when reviewing navigation performance, browser lifecycle events, or resume-from-memory behavior. Check the actual browser lifecycle and restore path, not only static code patterns.
热度
- GitHub 星标
- 75k
- 排名
- #2754
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。