Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Use navigator.onLine for modern browser #135

Closed
bennycode opened this issue Apr 21, 2015 · 6 comments
Closed

Use navigator.onLine for modern browser #135

bennycode opened this issue Apr 21, 2015 · 6 comments

Comments

@bennycode
Copy link

Hello,

I really like the "Offline" library but it would be great if it would make use of the navigator.onLine property for modern browser, because there is no need for them to do XML HTTP Requests all the time.

The navigator.onLine property works good in all modern browsers except Firefox, so it's definetly worth to be checked (compatibility). There are also callbacks for window.ononline and window.onoffline. 😃

@Southpaw17
Copy link

These properties work well when determining if the client has an active internet connection, but are not so good for determining if the user can actually talk to your server. For example, if the user has an active network connection but our servers are offline for some reason, we would want the client-side application to behave as if it's offline. This can only really be accomplished by poking the server to see if you can successfully communicate with it.

@bennycode
Copy link
Author

Yeah, you are totally right. Sorry. I misused "Offline" to check if the client is offline. 😀

@indolering
Copy link

While this only checks one aspect of the connection, adding it to the control flow would improve the UX. For example, if your strategy consists of simply disabling editing, listening for this event would preemptively prevent edit attempts. You could also improve the accuracy of the status indicator, alerting the user to a local connection issue and reducing the number of pointless "connecting" attempts.

@indolering
Copy link

Your event handler should probably include a time delay, rechecking navigator.online a few seconds later to allow for a portable to recover from temporary connection issues (like cycling sleep states or switching connections).

@indolering
Copy link

It appears as if the code already uses this (but using event handlers instead of check in the global variable), but the implementation is problematic as it trusts the "offline" signal entirely. No it doesn't, misread the code. I still think 100ms is a bit too eager, I would wait a full second or so.

I now disagree with preventing reconnection attempts based on the status of the global, there are probably edge cases where the offline event would not be reliable.

@indolering
Copy link

At any rate, please close this ticket.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants