Created
November 6, 2019 18:24
-
-
Save acortelyou/ee3424273295b609a25d108c5218ca6a to your computer and use it in GitHub Desktop.
Reload a page when modified on the server
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
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