is-offline
A tiny (174B) library to detect `offline` status & respond to changes in the browser.
is-offline Explanation
This is a tiny library that tells your web app whether the user is connected to the internet or not, and alerts you whenever that status changes. Instead of building your own network detection code, you can use this 174-byte package to handle it reliably across browsers.
The library gives you two main tools. The first is check(), which you can call anytime to ask "am I offline right now?" and get back a true or false answer. The second is watch(), which lets you set up a listener that automatically triggers whenever the user goes offline or comes back online—perfect for pausing uploads, showing a "you're disconnected" message, or retrying failed requests. When you're done watching, you can call the function it returns to turn off that listener.
This is useful for any web app where connection status matters. A note-taking app might automatically save drafts when online but queue changes for later if the user goes offline. A video player could pause and buffer ahead when the connection is good, or switch to lower quality if it drops. A map app could cache tiles for offline browsing. Any time you want to adapt your app's behavior based on whether the user can reach your servers, this library handles the detection work for you, and it does it in an extremely compact way—small enough that it barely adds to your app's download size.
The library ships in multiple formats so it works whether you're using modern JavaScript modules, older CommonJS packages, or even just dropping it into an HTML script tag. The API is straightforward: call check() once if you just need a snapshot, or call watch() to stay informed about every change.