david-li0406/meta-skill-evloving/service-worker-updates
Claude Code and agent skill by david-li0406/meta-skill-evloving
- community
Checking that the SKILL.md file is still in the repository.
Guide for modifying service worker caching. Edit sw-template.js (not sw.js), run yarn prebuild after changes.
Install
npx vskill@latest install david-li0406/meta-skill-evloving/service-worker-updatesSKILL.md
The same SKILL.md was published earlier as david-li0406/meta-skill-evloving/service-worker-updates.
Service Worker Updates Skill
Purpose
Guide for modifying the service worker caching strategy. Prevent common mistakes that break offline functionality.
⚠️ CRITICAL: Never Edit public/sw.js Directly
The public/sw.js file is generated and will be overwritten.
Always edit: public/sw-template.js
How Service Worker Generation Works
The build script:
- Reads
sw-template.js - Replaces
{{API_ORIGIN}}placeholder withNEXT_PUBLIC_API_URLorigin - Writes output to
public/sw.js
When to Run Regeneration
Run yarn prebuild after changing sw-template.js:
Note: yarn build alone does NOT run prebuild. Environment-specific builds (build:development|staging|production) do include it.
Service Worker Template Structure
Caching Strategies
| Strategy | Use Case | Example | |
|---|---|---|---|
CacheFirst | Static assets, images | Fonts, icons | |
NetworkFirst | API calls, dynamic data | Events, news | |
StaleWhileRevalidate | Balance freshness/speed | Category lists |
Adding New Cache Rules
1. Edit Template
2. Regenerate
3. Test
Common Patterns
Cache API Responses
Cache Static Assets
Offline Fallback
Environment Variable
The {{API_ORIGIN}} placeholder is replaced with the origin from NEXT_PUBLIC_API_URL:
Debugging Service Worker
- Chrome DevTools > Application > Service Workers
- Check "Update on reload" during development
- Use "Bypass for network" to test without caching
- Clear storage if seeing stale behavior
⚠️ CRITICAL: Always Use ignoreVary: true
Next.js App Router adds Vary headers (rsc, next-router-state-tree, next-router-prefetch, etc.) to responses. Without ignoreVary: true, service worker cache matching fails because these headers differ between request types (RSC navigation vs client fetch vs direct load).
Note: This addresses Workbox service worker cache matching, not the underlying Next.js dynamic route issue (which relates to Cache-Control: private/no-store when Server Components call headers() or cookies()). The ignoreVary: true option allows the SW to treat the same URL as one cache entry regardless of Vary header differences.
Always add `matchOptions` with `ignoreVary: true`:
Without this, the same URL may be fetched multiple times and cached as separate entries, causing:
- Wasted bandwidth
- Slower navigation (false cache misses)
- Unreliable offline behavior
Common Mistakes
- Editing sw.js directly → Changes lost on rebuild
- Forgetting yarn prebuild → Template changes not applied
- Wrong API_ORIGIN → Cache rules don't match
- Too aggressive caching → Users see stale data
- No cache expiration → Cache grows forever
- Missing `ignoreVary: true` → Cache misses due to Next.js
Varyheaders
Checklist for SW Changes
- [ ] Editing
sw-template.js(notsw.js)? - [ ] Running
yarn prebuildafter changes? - [ ] Using appropriate cache strategy?
- [ ] Setting cache expiration limits?
- [ ] Adding
matchOptions: { ignoreVary: true }to strategies? - [ ] Testing in DevTools > Application?
- [ ] Testing offline behavior?
Files to Reference
- public/sw-template.js - Source template (EDIT THIS)
- public/sw.js - Generated output (DO NOT EDIT)
- scripts/generate-sw.mjs - Build script
- app/offline/page.tsx - Offline fallback page
Security
- Security scanPassed, 90 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 repositoryCheckingskill-flow/data/skills-refined-skillclaw-36k/skillsmp/service-worker-updates/SKILL.md
Popularity
- 7-day trend score
- 0
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/david-li0406/meta-skill-evloving/service-worker-updates)