Last active
January 2, 2017 20:26
-
-
Save leonardosnt/19008f5aeaa964d8f05517653086bc60 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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