I'm using web app from which i send data to server very frequently. Option for sending data should be disabled if app has no internet connection. Which is the fastest way to check from browser if you are online? I've used navigator.onLine
but it's unreliable because different browsers interpret it differently. My other solution was to put some plain file on server and attemp to reach it every time before sending. Code looked like this:
function serverReachable() {
var x = new XMLHttpRequest (),
s;
x.open(
"HEAD",
'http://servername/client/keepalive.txt',
false
);
try {
x.send();
s = x.status;
return ( s >= 200 && s < 300 || s === 304 );
} catch (e) {
return false;
}
}
Function serverReachable() does the job but is there any faster way to do this(by faster I mean faster in terms of time not code quantity)?