— Pixels Commander

[ In English, На русском ]

OnlineJS – lightweight and easy to use library to check your internet connection status and react on it

Detecting internet connection status with JavaScript is generic problem during mobile web applications or dynamic sites development and everybody solves it in his own way. Online JS is a compilation of best practices for detecting connection status, it`s reliable, fast, very lightweight and compatible with all popular frameworks library that is very easy to use.

Simple example

Include this library into your project and just check is window.onLine === true

Define window.onLineHandler or window.offLineHandler functions to handle status changes.

Library uses such optimizations:

  • checks status in background mode,
  • requests only headers to minimize traffic,
  • listens for window.online/offline events and verifies them.

P.S. I`m often asked: “Why library does not use navigator.onLine ?”. This property is a bit underhandled and inconsistent between different browsers. For many of them it only shows status of local network connection and for some versions of FireFox it depends only on autonomic mode settings. So using this property in critical tasks is not good idea. Online JS is a right way for serious project because library uses navigator.onLine only as one of possible triggers and then makes more tests of internet connection status. You can rely on Online JS.

GitHub repository

  • http://anykeytocreate.blogspot.com/ Eugene Krevenets (Hyzhak)

    смотрю проверка online дергает “http://www.pixelsresearch.com/online.php”, не боишься, что популярность положит сайт? 🙂

  • Anonymous

    Если не хочешь зависеть от сайта – можно переназначить window.onlineCheckURL
    А траффика я не боюсь – запрос статичный, если что возьму сервер помощнее 😉

  • pride

    Однозначно не самое популярное решение дергать страничку по таймеру. В чем плюсы?

  • Anonymous

    Какое решение на ваш взгляд будет работать лучше?

  • Morozzov

    Помню в одном AIR приложении через URLLoader по таймеру дергал google.com))

  • Anonymous

    Это заманчивый вариант и для JavaScript, с удовольствием бы поступил так. Жаль, что кросс – доменная политика JS требует специфических хедеров в ответе сервера, выставить которые можно только имея контроль над сервером.

  • Raul Padilla Calderon

    it work fine, thx