SwoffSwoff

Getting Started

Getting started with Swoff.

Prerequisites

  • Node.js 18+
  • A built project with static output (dist/, public/, etc.)
  • No existing service worker (or one you're ready to replace)

Install and init

npx @swoff/cli init

Interactive wizard: framework (auto-detected), output directory, navigation mode, caching strategy, features. Writes swoff.config.json. Use --yes to skip prompts.

Generate files

npx @swoff/cli generate

Creates swoff/ with SW template, injector, generator, client-injector (ESM + IIFE), storage/reset utilities, TS declarations. Feature-specific files (auth, adapters) only for enabled features.

Add build step

The generator must run after each build to embed the latest assets. Add to package.json:

"build": "vite build && node swoff/sw/generator.mjs"

Or run manually: node swoff/sw/generator.mjs

Include in your HTML

Project typeCode
Bundlerimport { initServiceWorker } from "./swoff/client-injector"; initServiceWorker();
No-bundler<script src="/swoff/client-injector.bundle.js"></script>

Verify

Open Chrome DevTools → Application > Service Workers. Check Cache Storage for swoff-precache, swoff-runtime, swoff-runtime-html.

What's next?

On this page