aicodedecode/awesome-muse-skills/service-worker-pro
Claude Code and agent skill by aicodedecode/awesome-muse-skills
- community
Checking that the SKILL.md file is still in the repository.
Control the network layer with Service Workers: caching strategies, offline support, background sync, and update flows. Use for offline-first web apps.
Install
npx vskill@latest install aicodedecode/awesome-muse-skills/service-worker-proSKILL.md
The same SKILL.md was published earlier as aicodedecode/awesome-muse-skills/service-worker-pro.
Service Worker Pro
A practical guide to Service Workers: the programmable network proxy in the browser — lifecycle, caching strategies, offline architectures, background sync, and the update flows that keep users on fresh code without breaking them.
Overview
A Service Worker (SW) sits between your page and the network: it intercepts requests and decides — cache, network, or both. This enables offline support, instant repeat loads, and background sync. It's also the foundation of push notifications. The SW runs in its own thread with its own lifecycle (install → activate → fetch), independent of any page — which is both its power and its sharp edges (stale caches, update races).
When to use
- Offline-capable web apps (see also pwa-patterns).
- Caching strategies for assets and API responses.
- Background sync for queued mutations.
- Push notification handling.
- Advanced prefetching/prerendering strategies.
Core concepts
- Lifecycle.
install(precache) →activate(cleanup old caches) →fetch(intercept). A new SW waits until all tabs using the old one close (skipWaiting()+clients.claim()to take over immediately — use deliberately). - Scope. SW controls pages under its registration path. Register at root (
/sw.js) for full-site control. - Cache API.
caches.open('v1')— programmatic cache storage, separate from HTTP cache. Version cache names; delete old versions on activate. - Strategies. Cache-first (immutable assets), network-first (fresh data, cache fallback), stale-while-revalidate (fast + fresh eventually), network-only, cache-only. Match strategy to resource type.
- Precache vs runtime. Precache the app shell at install (known URLs); cache runtime requests as they happen (API responses, images).
- Background Sync.
sync.register('send-queue')→ SW retries when online — for queued mutations. One-shot; for periodic, Periodic Background Sync (limited support). - Update flow. Byte-difference check on navigation → new SW installs → waits → activates. UX: notify "new version available" → user refreshes, or auto-
skipWaitingfor non-critical apps.
Practical workflow
1. Register.
2. Precache + strategies (vanilla).
(Or use Workbox — recommended over hand-rolling for production.)
3. Offline fallback. Navigation requests failing → serve cached /offline.html. API failing → serve cached response with a flag, or a structured offline error the app handles.
4. Background sync for mutations.
5. Update UX. updatefound → show "Update available — refresh" snackbar → on click, registration.waiting.postMessage({ type: 'SKIP_WAITING' }) → controllerchange → location.reload().
Common pitfalls
- Caching the SW file itself. If
/sw.jsis cached with a long TTL, updates never arrive. Serve itCache-Control: no-cache(revalidate every time). - Over-aggressive precaching. Precaching everything = slow install, wasted bandwidth. Precache the shell; runtime-cache the rest.
- Stale-forever bugs. Cache-first on HTML/API without versioning = users stuck on ancient content. Version caches; prefer SWR/network-first for HTML.
- Update races.
skipWaitingmid-session can break in-flight app state (old page, new cached assets). For complex apps, prompt the user instead of forcing. - Opaque responses. Cross-origin
no-corsresponses are opaque — cacheable but inscrutable (can't check status). Prefer CORS-enabled endpoints. - Quotas. Cache + IndexedDB share origin storage (browser-managed, evictable). Don't treat it as infinite; handle
QuotaExceededError. - Dev confusion. SW caching during development = "my changes aren't showing". Unregister in dev, or use dev-only bypass. Chrome DevTools → Application → Service Workers → "Update on reload" + "Bypass for network".
- Scope mistakes. Registering
/app/sw.jscontrols only/app/*. Root registration for site-wide control. - Untested offline. "Works offline" claimed, never tested. DevTools offline mode + real airplane-mode tests on device.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/service-worker-pro/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
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/aicodedecode/awesome-muse-skills/service-worker-pro)