Search code examples
progressive-web-apps

How to know if a device is connected to a working internet connection in PWA


When creating a progressive web app how can i know that a mobile device is connected to a working internet connection cause it can be connected but not working.


Solution

  • The saying, "You never know until you try" is pertinent here. At the moment you want to check whether there is connectivity, simply fetch a remotely hosted resource with a cache-busting technique. It's generally best practice for that resource to be tiny in file size if you need to check regularly and often (such as 1×1 pixel gif). If you receive a network response in the 200 range, you have connectivity. Otherwise, for the moment at least, you probably don't.