disableBFCacheBeforeHistoryTravel: function() {
// https://www.google.com/search?q=BFCache
// 情景:将要跳转到某一被 BFCache 了的页面,希望该页面强制刷新
// 用法:在 history.go() history.back() 之前调用此方法
localStorage.setItem('bfcache_disable', true);
},
preventBFCacheOnCurrentPageBeforeHistoryTravel: function() {
// https://www.google.com/search?q=BFCache
// 情景:当前页面产生了 BFCache ,之后可能会再跳回来,此时会发生页面部分 js 没有执行,需要强制重新刷新的情况
// 用法:在 location.href = 'xxx' / location.replace 之前 或 a.onclick 之时,调用此方法
localStorage.removeItem('bfcache_disable');
var timer;
var stopLoop = function() {
clearInterval(timer);
};
var loop = function() {
if(localStorage.getItem('bfcache_disable')) {
localStorage.removeItem('bfcache_disable');
stopLoop();
location.reload();
}
};
timer = setInterval(loop, 100);
//auto stop after 5000 seconds
setTimeout(stopLoop, 5000);
}