As developers, we sometimes get used to our great broadband in our offices and localhost being the fastest site ever with no network issues.
In fa...
For further actions, you may consider blocking this person and/or reporting abuse
Awesome post. It's not something I have really thought about before but I will start doing now
Yes, definitely something to look into π
Thanks, Short and to the point article. I think most
PWA
apps does this.Not without diving into a service worker. It'll also only catch when network requests succeed/fail so you could add this to a PWA to create a richer experience. So this will actually update your UI when your connectivity changes rather than when you're actually making requests.
navigator.online
on it's own for checking if a user is really online is not working. It only lets you know if there is network access, which isn't the same as "connected to the internet". So basically, it is useless, unless you application works in a closed off network or something....I've left a link to some of the issues with
navigator.online
in the article. Definitely not a good solution alone. The event listeners are the real magic for checking when people are using apps on the move.Great explanation. I feel like this really contextualizes how to implement this.
Thanks Ben! Glad you enjoyed it. π
Nice explanation!
Nevertheless, I recently had to implement such a feature and found the navigator
online/offline
not really reliable. Especially if you've to support different devices, browsers, OS and Frameworks(Electron, Cordova,...).I went with a workaround consisting of the navigator API and a fetch request to an external endpoint to really make sure a connection exists.
Hope this helps, if someone struggles with the raw navigator API.
Totally agree, this isn't a silver bullet! This is just one of the ways to handle things. I use this combined with service workers and error handling.
That will help a lot! :)
I wonder, is there a straightforward implementation to verify whether or not Internet is accessible when "online"?
When it comes to the actual network requests and that I find service workers are one of the best ways to serve up different things based on failed requests.
It really don't work for network disconnect, it only listens to dev tool throttling, please confirm if anyone else have faced this issue
also MDN web docs state it's isn't fully reliable for checking & they recommend to use XHR response for network offline confirmation
Thanks
Great tutorial! Thanks for sharing.
navigator.online cannot be trusted: there's the "liefi" situation where you appear to be online but still cannot access the internet.
Thank you Niall. I have learned something new.
Glad it helped π
Awesome! π
Thanks π
Awesome
Cheers π
While the
navigator.onLine
thingy is a neat trick, it's not that useful information.Knowing if connections to back-end services are up/down would be something.
This is cool, thanks for sharing with us Niall
Glad you enjoyed it!