html 后退缓存,浏览器前进/后退缓存(BF Cache)

浏览器前进/后退缓存(Backward/Forward Cache,BF Cache)是指浏览器在前进后退过程中,

会应用更强的缓存策略,表现为 DOM、window、甚至 JavaScript 对象被缓存,以及同步 XHR 也被缓存。

这一现象在移动端浏览器尤为常见,除 Chrome for Android、Android Browser 之外的浏览器基本都会触发。

BF Cache 本来是一项浏览器优化,但在某些情况下(比如前端路由的 Web App)会引起困惑。

本文主要讨论 BF Cache 的行为、如何检测 BF Cache 缓存、以及如何 workaround。

缓存行为

BF Cache 是一种浏览器优化,HTML 标准并未指定其如何进行缓存,因此缓存行为是与浏览器实现相关的。

User agents may discard the Document objects of entries other than the current entry that are not referenced from any script, reloading the pages afresh when the user or script navigates back to such pages. This specification does not specify when user agents should discard Document objects and when they should cache them. – Session history and navigation, WHATWG

Desktop Chrome:阻塞的资源和同步发出的 XHR 都会被缓存,但不缓存渲染结果。因此可以看到明显的载入过程,此时脚本也会重新执行。

Chrome for Android


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部