Created
July 14, 2018 07:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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