Skip to content

Instantly share code, notes, and snippets.

@Troland
Created July 14, 2018 07:16
Show Gist options
  • Save Troland/4b9090935f82ebf946d58c42a271ea93 to your computer and use it in GitHub Desktop.
Save Troland/4b9090935f82ebf946d58c42a271ea93 to your computer and use it in GitHub Desktop.
Detect Backward/Forward Cache alias BF cache, if render from cache then reload page.
window.addEventListener('pageshow', (event) => {
// detect Backward/Forward Cache alias BF cache
// if render from cache then reload page
if (event.persisted || window.performance &&
window.performance.navigation.type === 2) {
window.location.reload();
}
};
//jquery 中没有这个对象,需要用原生事件对象
$(window).on('pageshow', (event) => {
// detect Backward/Forward Cache alias BF cache
// if render from cache then reload page
if (event.originalEvent.persisted || window.performance &&
window.performance.navigation.type === 2) {
window.location.reload();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment