Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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
You can’t perform that action at this time.