Last active
August 29, 2015 14:00
-
-
Save slikts/11050304 to your computer and use it in GitHub Desktop.
Ping a server with HEAD requests until it's up and then reload
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
function reload(url, delay) { | |
url = url || '/'; | |
delay = delay || 10; | |
var req = new XMLHttpRequest(); | |
req.onload = window.location.reload.bind(window.location); | |
req.onerror = setTimeout.bind(null, reload.bind(null, url, delay), delay); | |
req.open('head', url, true); | |
req.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment