Skip to content

Instantly share code, notes, and snippets.

@acortelyou
Created November 6, 2019 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acortelyou/ee3424273295b609a25d108c5218ca6a to your computer and use it in GitHub Desktop.
Save acortelyou/ee3424273295b609a25d108c5218ca6a to your computer and use it in GitHub Desktop.
Reload a page when modified on the server
var origModified = "";
var check = function(){
var xhr = new XMLHttpRequest();
xhr.open("HEAD", window.location.href, true);
xhr.onreadystatechange = function() {
if (this.readyState != 2) return;
var lastModified = xhr.getResponseHeader("Last-Modified");
if (!origModified) origModified = lastModified;
else if (origModified != lastModified) location.reload(true);
};
xhr.send();
};
setInterval(check, 120000);
check();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment