jgamaraalv/ts-dev-kit/service-worker
Claude Code and agent skill by jgamaraalv/ts-dev-kit
- community
Checking that the SKILL.md file is still in the repository.
Service Worker API implementation guide — registration, lifecycle management, caching strategies, push notifications, and background sync. Use when: (1) creating or modifying service worker files (sw.js), (2) implementing offline-first caching (cache-first, network-first, stale-while-revalidate), (3) setting up push notifications or background sync, (4) debugging service worker registration, scope, or update issues, (5) implementing navigation preload, (6) user mentions 'service worker', 'sw.js', 'offline support', 'cache strategy', 'push notification', 'background sync', 'workbox alternative', or 'PWA caching'.
Install
npx vskill@latest install jgamaraalv/ts-dev-kit/service-workerSKILL.md
Service Worker
Table of Contents
- Constraints
- Lifecycle
- Registration
- Install / Activate / Fetch Events
- Common Pitfalls
- Next.js Integration
- Reference files
<constraints>
Constraints
- HTTPS required (localhost exempt for dev)
- No DOM access — runs on separate thread
- Fully async — no synchronous XHR, no localStorage
- No dynamic
import()— only staticimportstatements - Scope defaults to the directory containing the SW file
selfrefers toServiceWorkerGlobalScope
</constraints>
<quick_reference>
Lifecycle
- Register from main thread via
navigator.serviceWorker.register() - Install event fires once — use to pre-cache static assets
- Wait — new SW waits until all tabs using old SW are closed (skip with
self.skipWaiting()) - Activate event fires — use to clean up old caches
- Fetch events start flowing — SW controls page network requests
A document must reload to be controlled (or call clients.claim() during activate).
Updating a Service Worker
- Browser byte-compares the SW file on each navigation (or every 24h)
- New version installs in background while old version still serves
- Increment the cache name (e.g.,
v1→v2) in the new version - Delete old caches in the
activatehandler - Call
self.skipWaiting()ininstallto activate immediately - Call
self.clients.claim()inactivateto take control of open pages
DevTools
- Chrome:
chrome://inspect/#service-workersor Application > Service Workers - Firefox:
about:debugging#/runtime/this-firefoxor Application > Service Workers - Edge:
edge://inspect/#service-workersor Application > Service Workers
Unregister, update, and inspect caches from the Application panel. Use "Update on reload" checkbox during development.
</quick_reference>
<examples>
Registration
Scope rules:
- SW at
/sw.jscan control/and all subpaths - SW at
/app/sw.jscan only control/app/by default - Broaden scope with
Service-Worker-Allowedresponse header
Install Event — Pre-cache Assets
waitUntil(promise) — keeps install phase alive until the promise settles. If rejected, installation fails and the SW won't activate.
Activate Event — Clean Up Old Caches
Fetch Event — Intercept Requests
respondWith(promise) — must be called synchronously (within the event handler, not in a microtask). The promise resolves to a Response.
For caching strategy patterns (cache-first, network-first, stale-while-revalidate), see references/caching-strategies.md.
Navigation Preload
Avoid the startup delay when a SW boots to handle a navigation:
Communicating with Pages
Next.js Integration
In Next.js, place the service worker file in public/sw.js. public/sw.js is intentionally plain JS (not processed by Next.js build pipeline). Register it from a client component:
Add to root layout. Next.js serves public/ files at the root, so /sw.js scope covers /.
</examples>
<gotchas>
Common Pitfalls
- Response cloning —
response.clone()before both caching and returning, since body streams can only be read once - Opaque responses — cross-origin fetches without CORS return opaque responses (status 0).
cache.add()will refuse them. Usecache.put()but you can't inspect the response - waitUntil timing — call
event.waitUntil()synchronously within the event handler, not inside an async callback - Scope ceiling — a SW cannot control URLs above its own directory unless
Service-Worker-Allowedheader is set - No state persistence — the SW may terminate at any time when idle. Don't store state in global variables — use Cache API or IndexedDB
</gotchas>
<references>
Reference files
- Caching strategies (cache-first, network-first, stale-while-revalidate): references/caching-strategies.md
- Push notifications & background sync (push subscription, push events, background sync): references/push-and-sync.md
- API quick reference (
Cache,CacheStorage,FetchEvent,Clients,ServiceWorkerRegistration,ServiceWorkerGlobalScope): references/api-reference.md
</references>
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/service-worker/SKILL.md
Popularity
- Repository stars
- 12
- Repository npm downloads, 7 days
- 55
- 7-day trend score
- 28
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 16 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jgamaraalv/ts-dev-kit/service-worker)