Features
What Swoff provides — CLI-generated code, zero runtime deps.
Features
Swoff is a CLI that generates code you own. Zero runtime dependencies — the generated files are all you need.
CLI Commands
| Command | Purpose |
|---|---|
init | Create swoff.config.json and swoff/ directory |
generate | Generate SW + supporting files from config |
add | Toggle a feature on in swoff.config.json |
clean | Remove all Swoff traces (swoff/, config, version.json) |
validate | Validate config against JSON schema |
Generated Files
The CLI outputs to two locations:
dist/— service worker (sw-v{version}.js) and version manifest (version.json)swoff/— client-side helpers (injector, fetch wrapper, cache, PWA install, etc.)public/manifest.json— Web App Manifest (only ifpublic/exists and no existing manifest)
Features Toggle
Configure via swoff.config.json:
Core (enabled by default)
| Feature | Type | Default | Generates |
|---|---|---|---|
versionedSw | boolean | true | Versioned SW with install/activate lifecycle |
pwa | object | { enabled: true, preventDefaultInstall: false } | PWA install handler + manifest.json |
crossTabSync | boolean | true | Cross-tab cache invalidation (requires tagInvalidation) |
tagInvalidation | boolean | true | URL-based cache tag generation + invalidation |
clientRegistration | boolean | true | sw-injector.js with version checking and update consent |
Optional (disabled by default)
| Feature | Type | Default | Generates |
|---|---|---|---|
mutationQueue | boolean | false | Store offline writes, sync on reconnect |
backgroundSync | boolean | false | Background Sync API (Chrome/Edge) |
auth | object | { enabled: false, type: "bearer", refreshPath: "/api/refresh", userEndpoint: "/api/me" } | Auth token storage (memory-only), auth-aware fetch, user cache |
indexeddb | object | { enabled: false, name: "app-db", stores: [] } | IndexedDB CRUD, migrations, quota management |
Service Worker Behavior
| Field | Type | Default | Description |
|---|---|---|---|
autoRegister | boolean | true | Auto-register new SW versions on page load |
autoActivate | boolean | false | Auto-activate via skipWaiting after registration |
strategy.default | string | "cache-first" | Default caching strategy |
strategy.patterns | object | {} | Per-URL pattern strategy overrides |
strategy.mode | string | "all" | Controls which requests are processed by the SW cache strategy system |
strategy.clearRuntimeOnUpdate | boolean | false | Clear runtime cache on SW activate (security measure) |
strategy.normalizeKey | boolean | false | Normalize cache keys by sorting query params |
strategy.ignoreQueryParams | string[] | [] | Query params to ignore when matching cache keys |
navigation.mode | string | "spa" | SPA navigation fallback or default strategy |
navigation.preload | boolean | true | Enable Navigation Preload API |
navigation.fallback | string | "/index.html" | Fallback URL for SPA navigation mode |
Invalidation Tags
The invalidation-tags.js helper parses REST URLs into cache tags:
generateTags("/api/todos/42")
// → ["todos", "todo:42"]Tagged cache entries are invalidated automatically after mutations — no manual cache management needed.
Service Worker Architecture
The generated SW uses a versioned lifecycle:
- Install — precache app shell assets, skip on reinstall
- Activate — claim clients, delete old caches
- Fetch — apply per-URL caching strategies with tag-based invalidation
Update flow:
- New SW detected → user consent prompt (configurable via
autoActivate) - On approval → skipWaiting → controllerchange → reload
- Cross-tab sync broadcasts invalidations to all open tabs
Swoff vs Traditional PWA Libraries
| Swoff | Traditional PWA Libraries | |
|---|---|---|
| Dependencies | Zero runtime deps | npm packages |
| Control | You own the generated code | Library updates can break your app |
| Updates | Consent-based, versioned | Often automatic |
| Offline | Guaranteed by architecture | Depends on library |
| Framework | Agnostic | Often framework-specific |
Next Steps
- Schema Reference — full field list
- CLI Reference — command overview
Swoff