Last active
August 23, 2016 15:55
-
-
Save adjavaherian/2537197afde6bbd3811221f65c2a76ef to your computer and use it in GitHub Desktop.
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
<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