I have an web application with a lot of JavaScript. If I update some .js files on the server and I forget to rename them, I have implemented function below in case of an error - the page will be completely reloaded, giving up the cached files:
window.addEventListener('error', function (e) {
if(confirm("The application encountered an unexpected problem. Click OK to try restarting it")){
window.location.reload(true);
}
}
Everything is working well. But not on Chrome. It seems that window.location.reload(true)
do not load a fresh version of files from server, because the status code in browser is:
Status Code: 200 OK (from memory cache)
How can I make Chrome based browsers to get a fresh version of all files from server with JavaScript in case of an error? Keep in mind that all .js files are using a long term cache directives and this is the way I want to stay.
Later edit
This is my solution so far (implemented in server side):
<?php
$path = getcwd() . '/';
function lastFileStamp($file){
echo '"'.$path.$file.'?'.filemtime($path.$file).'"';
}
?>
<link rel="stylesheet" href=<?php lastFileStamp("../common/themes/test.css");?> />
<script src=<?php lastFileStamp("../common/date.js");?> ></script>
...
But this solution is not an answer to the initial question: How can I make Chrome based browsers to get a fresh version of all files from server with JavaScript in case of an error?