DEV Community

Discussion on: Detecting if the user is online with JavaScript

Collapse
 
uploadcare profile image
Uploadcare

This API is too unstable and usually you don't want to use it in production, because online in terms of user's browser may not be the same as online in terms of the user themselves.

There are better ways to detect offline:

  1. Long-pooling request to the server.
  2. Periodical check for a dummy image/resource without caching.
  3. Showing such a status only when the user's request fails due to unstable network.

Relying on navigator.onLine only you may scare your user. So, please do not.