title: Fastest way to check connection status from browser
body: <p>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 <code>navigator.onLine</code> 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:</p>
  
  <pre><code>function serverReachable() {
    var x = new XMLHttpRequest (),
    s;
    x.open(
      "HEAD",
      'http://servername/client/keepalive.txt',
      false
    );
    try {
      x.send();
      s = x.status;
      return ( s &gt;= 200 &amp;&amp; s &lt; 300 || s === 304 );
    } catch (e) {
      return false;
    }
  }
  </code></pre>
  
  <p>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)?</p>