如何用 performance.navigation 判断页面刷新并清理缓存

张开发
2026/4/17 2:05:24 15 分钟阅读

分享文章

如何用 performance.navigation 判断页面刷新并清理缓存
performance.navigation 已被废弃Chrome 85、Firefox 80 起完全移除应改用 performance.getEntriesByType(navigation)[0].type 判断导航类型如 reload 表示刷新。performance.navigation 已被废弃现代浏览器中不应再使用它来判断页面刷新或清理缓存。为什么 performance.navigation 不可用从 Chrome 85、Firefox 80 等版本起performance.navigation及其 type 和 redirectCount 属性已被完全移除。调用它会返回 undefined 或抛出异常。W3C 标准已用 PerformanceNavigationTiming 接口替代但该接口也不直接暴露“是否刷新”这一语义而是提供更底层的导航类型信息。替代方案用 performance.getEntriesByType(navigation)通过获取当前导航条目检查其 type 字段可间接判断用户行为navigate正常跳转如点击链接、location.href 跳转 reload明确由刷新触发F5、CtrlR、右键刷新、地址栏回车后点刷新图标 back_forward前进/后退含 bfcache 恢复 prerender预渲染较少见示例代码 RedClaw 百度推出的手机端万能AI Agent助手

更多文章