Skip to content

Instantly share code, notes, and snippets.

@leonardosnt
Last active January 2, 2017 20:26
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 leonardosnt/19008f5aeaa964d8f05517653086bc60 to your computer and use it in GitHub Desktop.
Save leonardosnt/19008f5aeaa964d8f05517653086bc60 to your computer and use it in GitHub Desktop.
function refreshOnChanges(checkInterval) {
setInterval(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', window.location.toString());
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
var changed = parseFloat(xhr.getResponseHeader("Changed"));
if (changed > window.performance.timing.navigationStart) {
location.reload(true);
}
}
}
xhr.send();
}, checkInterval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment