Your web app works offline. Three lines, zero config.
Automatic caching. Static assets (JS, CSS, images, fonts) are cached on first visit and served instantly on return. API calls go network-first with offline fallback.
Request queue. POST, PUT, DELETE requests that fail while offline are saved and automatically replayed when connectivity returns.
No setup. No Workbox, no config file, no service worker file to host, no build plugin. Just init().
import { init } from '@lorb/offline-auto';
init();
// Your app now works offline.npm install @lorb/offline-autoimport { init } from '@lorb/offline-auto';
init();
// Static assets: cached automatically (cache-first)
// API calls: network-first, falls back to cache when offline
// Failed writes: queued and replayed on reconnectinit({
excludePaths: ['/api/auth', '/api/realtime'],
});init({
onStatusChange: (online) => {
document.querySelector('.status').textContent =
online ? 'Connected' : 'Working offline';
},
});init({ cacheName: 'my-app-v2' });
// Old caches from previous versions are automatically cleaned up.const cleanup = init();
// Later: unregister the service worker and clear all caches
cleanup();| Request type | Strategy | Offline behavior |
|---|---|---|
Static assets (.js, .css, .png, .woff2, ...) |
Cache-first | Served from cache |
| GET API calls | Network-first | Falls back to cached response |
| POST / PUT / DELETE | Network-first | Queued in IndexedDB, replayed on reconnect |
Storage: Uses OPFS when available (larger quota), falls back to Cache API.
Chrome and Edge. Firefox and Safari don't support blob-URL service worker registration.
import { isSupported } from '@lorb/offline-auto';
if (isSupported()) {
init();
}| Export | Description |
|---|---|
init(options?) |
Register service worker. Returns cleanup() function |
isSupported() |
Check browser compatibility |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
cacheName |
string |
'offline-auto-v1' |
Cache storage name |
excludePaths |
string[] |
[] |
URL paths to skip |
onStatusChange |
(online: boolean) => void |
— | Connectivity change callback |
𖦹 MIT — Lorb.studio