NekR / offline-plugin

Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)
MIT License
4.52k stars 295 forks source link

Determine if app is running in offline mode #359

Closed adi-darachi closed 6 years ago

adi-darachi commented 6 years ago

It feels a bit obvious but I could not find it the documentation. I'm looking for a way to determine if the app is running in offline mode.

Thanks in advance!

DJTB commented 6 years ago

https://github.com/ReactTraining/react-network

the main code is window.navigator.onLine

NekR commented 6 years ago

Yes, navigator.onLine and online and offline events on window. See example here: https://github.com/NekR/offline-plugin-pwa/blob/6a0e535514457f7c92e8b5d9f4ec2004e685bec1/src/main.js#L52-L69