Skip to content

Instantly share code, notes, and snippets.

@gitawego
gitawego / serverReachable.js
Created December 10, 2012 14:00
a simple way to detect if server is reachable
//event naviagor.onLine isn't fiable.
function serverReachable() {
// IE vs. standard XHR creation
var x = new ( window.ActiveXObject || XMLHttpRequest )( "Microsoft.XMLHTTP" ),
s;
x.open(
// requesting the headers is faster, and just enough
"HEAD",
// append a random string to the current hostname,
// to make sure we're not hitting the cache