it recently came to my attention that simply using window.location.reload() is not a hard refresh i.e. cache is cleared along with the refresh. I was then told to use window.location.reload(true) but I discovered this has since been deprecated.
I am not sure how to determine whether or not the cache has been cleared, so I feel that any method that refreshes the page simply won't cut it for what I need to do, as I cannot tell if cache is being cleared.
I have seen various other approaches including window.location.href = window.location.href; but have seen comments saying this does not clear cache.
I have seen people say that using a "POST" method should do the trick, but I am not sure how to implement this into my current code. I am using a MatSnackBar to prompt the user to refresh the page when a newer version of the app has been released. Here is the code for that SnackBar:
showSnackbar(versionFromHTTP: string, appVersion: string): void {
const httpList = versionFromHTTP.split('.');
const appList = appVersion.split('.');
if ((httpList[0] === appList[0]) && (httpList[1] === appList[1])){
let snack = this.snackBar.open('We\'ve made new updates! Please refresh your browser to get the latest updates.', 'Refresh now');
snack.onAction().subscribe(() => {
window.location.href = window.location.href;
});
}
else{
let snack = this.snackBar.open('We\'ve made new updates - some features may not work correctly until you refresh your browser.', 'Refresh now');
snack.onAction().subscribe(() => {
window.location.href = window.location.href;
});
}
}