跳到正文
Skillpedia
网站与界面(前端)75k · #2754

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/back-forward-cache/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 unload listener - it is the most common bfcache blocker
  • Use pagehide and pageshow instead of assuming every navigation reloads
  • Refresh time-sensitive state when pageshow.persisted is true
  • Keep beforeunload conditional 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2754
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能