Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Simple Svelte component to detect offline & online changes.
s-offline is an open-source Svelte 3 component that detects when a browser goes offline or online and lets you show different UI for each state through named slots. It is maintained by Vinayak Kulkarni, released under the MIT license, and available on npm and CDN.
s-offline is a Svelte 3 component that listens for the browser's online and offline events and reports the connection status to your app. It takes an optional pingUrl prop (default https://google.com) to double-check connectivity by pinging that URL, and it produces a detectedCondition event with a boolean value so your components can react. The package is built with TypeScript, includes type definitions, and is distributed through npm, UNPKG, and jsDelivr. The library is maintained by Vinayak Kulkarni and is inspired by v-offline, a similar component for Vue.js.
online and offline events, so your Svelte app updates without manual polling.https://google.com) that is pinged to double-check whether the user is actually offline before the state changes.online and offline slots so you can render any Svelte markup (text, emoji, icons) depending on the current state.SOffline script on UNPKG and jsDelivr, allowing use without a bundler.detectedCondition event to queue network requests, disable forms, or show a message that data will sync later.offline slot and a happy state in the online slot.detectedCondition event and prevent form submission or warn users when a ping to your own API endpoint (set via pingUrl) fails.SOffline in a layout and drive a store or global state from the detectedCondition event to reflect connectivity across pages.The component subscribes to the browser's online and offline events and pings the URL provided in the pingUrl prop (default https://google.com) to double-check the actual network state. When the state changes, it emits a boolean value through the detectedCondition event and toggles the rendered slot between online and offline.
Run npm install --save s-offline in a Svelte 3 project, or load the pre-built script from UNPKG or jsDelivr, where it is available globally as SOffline.
The README lists Svelte 3 as the requirement. If you are using Svelte 4 or 5, the component may need testing or a compatibility check before use.
SOffline accepts one optional prop: pingUrl, a string that defaults to https://google.com. It is the URL pinged to double-check whether the user is offline or online.
The README states that the detectedCondition event returns a value (described as a boolean) every time the network condition changes, so you can pass it to a handler like handleNetworkChange.
Yes, the project is released under the MIT license and is available on GitHub, where it has a public repository and contributions are welcome.
