offline
Automatically display online/offline indication to your users
A tiny JavaScript library that detects when your website visitors lose internet access, shows a notification, and automatically retries any requests that failed while they were offline.
Offline is a small JavaScript library that detects when your website visitors lose their internet connection and shows them a notification. When the connection comes back, it hides the notification and automatically retries any web requests that failed while the user was offline. The library was created by HubSpot and is no longer actively maintained, though it still works for its intended purpose.
The detection works by watching for failed network requests in the background. When something fails, the library checks whether the connection is truly down by trying to load a small resource such as your site's favicon. If that also fails, it marks the connection as down and shows the offline indicator. Once the connection returns, it quietly replays any requests that were held back so users do not lose data they were trying to send.
The UI piece comes from a CSS theme file. Several visual themes are available, and you can leave the CSS out entirely if you only want the JavaScript detection and retry behavior without any visible indicator. The whole library weighs about 3 kilobytes when minified and compressed, and it has no external dependencies.
Configuration options let you control how often the library retests the connection, whether to intercept and replay failed requests, and what URL to hit when checking connectivity. The README also mentions an optional snake game that can appear for users while they wait for the connection to return, though that is a separate file not included in the default build.
The library supports modern browsers as well as Internet Explorer 8 and above. Some browsers do not support native offline events, so the library falls back to its own polling approach in those cases.
Where it fits
- Add an offline banner to your website that appears automatically when a visitor loses their connection
- Automatically replay failed form submissions or API calls once the user's internet comes back
- Include a themed offline indicator with no external dependencies in any web project
- Configure polling intervals and retry logic for a custom connectivity-check URL