Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【转】浏览器往返缓存 #6

Open
zhongxia245 opened this issue Oct 23, 2019 · 1 comment
Open

【转】浏览器往返缓存 #6

zhongxia245 opened this issue Oct 23, 2019 · 1 comment

Comments

@zhongxia245
Copy link
Owner

zhongxia245 commented Oct 23, 2019

浏览器往返缓存 , 指的是浏览器或者 webview 中,使用手机自带的返回按钮,或者 history.go(-1) 回去后,页面没有刷新,导致页面上的数据还是旧的内容问题

LeuisKen/leuisken.github.io#6 这篇文章属于硬核型,分析了 chrome内科原码,然后给出解决方案。

具体是否可行,需要去尝试下。

@zhongxia245 zhongxia245 changed the title 浏览器往返缓存 【转】浏览器往返缓存 Dec 21, 2019
@zhongxia245
Copy link
Owner Author

解决方案

业务上添加如下代码:

// disable bfcache
try {
    var bfWorker = new Worker(window.URL.createObjectURL(new Blob(['1'])));
    window.addEventListener('unload', function () {
        // 这里绑个事件,构造一个闭包,以免 worker 被垃圾回收导致逻辑失效
        bfWorker.terminate();
    });
}
catch (e) {
    // if you want to do something here.
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant