Skip to content

Instantly share code, notes, and snippets.

@adjavaherian
Last active August 23, 2016 15:55
Show Gist options
  • Save adjavaherian/2537197afde6bbd3811221f65c2a76ef to your computer and use it in GitHub Desktop.
Save adjavaherian/2537197afde6bbd3811221f65c2a76ef to your computer and use it in GitHub Desktop.
<script type="text/javascript">
(function(){
var timestamp = 0;
var client = new XMLHttpRequest();
var interval = setInterval(setRefresh, 500);
console.log('setting refresh interval id...', interval);
function getTimestamp(callback) {
client.open("HEAD", "http://localhost:8001/archer/dist/app.js", true);
client.send();
client.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED) {
var ts = Date.parse(this.getResponseHeader('Last-Modified'));
callback(ts, timestamp);
}
}
}
function setRefresh() {
getTimestamp(function(newts, ts) {
if(ts === 0) {
timestamp = newts;
} else if(newts > ts) {
console.log('refreshing page...');
clearInterval(interval);
window.location.reload(false);
}
});
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment