正常情况下我们通过 history.back() 或者 history.go(-1) 返回上一级页面的时候,是不会刷新页面的。这种不刷新页面包含两种情况:
在 android 或者 pc 浏览器中看到的页面有刷新的效果,其实不是这样的,这个时候的所有的资源都是从缓存中加载来的。我们通过浏览器调试工具可以看到 from disk cache 或者 from memory cache。
在 ios 中甚至于返回到了上一页后,连上一页的脚本文件都没有执行; (其实不是没有执行,是执行了onpageshow)
window.addEventListener('pageshow', function(event) {
if(event.persisted) { // ios 有效, android 和 pc 每次都是 false
sessionStorage.removeItem('refresh');
location.reload();
}
});
https://www.jb51.net/article/165478.htm