Swoff Swoff

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

CommandPurpose
initCreate swoff.config.json and swoff/ directory
generateGenerate SW + supporting files from config
addToggle a feature on in swoff.config.json
cleanRemove all Swoff traces (swoff/, config, version.json)
validateValidate 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 if public/ exists and no existing manifest)

Features Toggle

Configure via swoff.config.json:

Core (enabled by default)

FeatureTypeDefaultGenerates
versionedSwbooleantrueVersioned SW with install/activate lifecycle
pwaobject{ enabled: true, preventDefaultInstall: false }PWA install handler + manifest.json
crossTabSyncbooleantrueCross-tab cache invalidation (requires tagInvalidation)
tagInvalidationbooleantrueURL-based cache tag generation + invalidation
clientRegistrationbooleantruesw-injector.js with version checking and update consent

Optional (disabled by default)

FeatureTypeDefaultGenerates
mutationQueuebooleanfalseStore offline writes, sync on reconnect
backgroundSyncbooleanfalseBackground Sync API (Chrome/Edge)
authobject{ enabled: false, type: "bearer", refreshPath: "/api/refresh", userEndpoint: "/api/me" }Auth token storage (memory-only), auth-aware fetch, user cache
indexeddbobject{ enabled: false, name: "app-db", stores: [] }IndexedDB CRUD, migrations, quota management

Service Worker Behavior

FieldTypeDefaultDescription
autoRegisterbooleantrueAuto-register new SW versions on page load
autoActivatebooleanfalseAuto-activate via skipWaiting after registration
strategy.defaultstring"cache-first"Default caching strategy
strategy.patternsobject{}Per-URL pattern strategy overrides
strategy.modestring"all"Controls which requests are processed by the SW cache strategy system
strategy.clearRuntimeOnUpdatebooleanfalseClear runtime cache on SW activate (security measure)
strategy.normalizeKeybooleanfalseNormalize cache keys by sorting query params
strategy.ignoreQueryParamsstring[][]Query params to ignore when matching cache keys
navigation.modestring"spa"SPA navigation fallback or default strategy
navigation.preloadbooleantrueEnable Navigation Preload API
navigation.fallbackstring"/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:

  1. Install — precache app shell assets, skip on reinstall
  2. Activate — claim clients, delete old caches
  3. 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

SwoffTraditional PWA Libraries
DependenciesZero runtime depsnpm packages
ControlYou own the generated codeLibrary updates can break your app
UpdatesConsent-based, versionedOften automatic
OfflineGuaranteed by architectureDepends on library
FrameworkAgnosticOften framework-specific

Next Steps

On this page