Skip to content

Instantly share code, notes, and snippets.

@mholtzhausen
Created July 15, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mholtzhausen/d706b0cde653ce910088 to your computer and use it in GitHub Desktop.
Save mholtzhausen/d706b0cde653ce910088 to your computer and use it in GitHub Desktop.
Fix Browser Page-Cache on pages that require reload for every view
(function () {
//For browsers that have an unmodified window.history object when navigating back
if (window.history.state != null && window.history.state.hasOwnProperty('historic')) {
if (window.history.state.historic == true) {
document.body.style.display = 'none';
window.history.replaceState({historic: false}, '');
window.location.reload();
} else {
window.history.replaceState({historic: true, last_visit: new Date()}, '');
}
} else {
window.history.replaceState({historic: true, last_visit: new Date()}, '');
}
//For browsers that disable page cache when an onunload handler exists
window.onunload = function () {
};
// For browsers that have the event.persisted property set for pages that have been cached
window.onpageshow = function (event) {
if (event.persisted) {
document.body.style.display = 'none';
window.location.reload();
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment