[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EVXVQ3JS4BC54YBM8AWKMJ":3,"skill-same:01M7EVXVQ3JS4BC54YBM8AWKMJ":45},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M7EVXVQ3JS4BC54YBM8AWKMJ","ams-service-worker-pro",null,"TanNhatCMS\u002Fjarvis","TanNhatCMS","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F113796420?v=4","01M753MV17KG5CD3152G3WQEQY","KietNT","01M7EKEDYVYQ6PWVJJMZ911VMX",0,"MIT","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fams-service-worker-pro\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: service-worker-pro\ndescription: Control the network layer with Service Workers: caching strategies, offline support, background sync, and update flows. Use for offline-first web apps.\ncategory: web-development\n---\n\n# Service Worker Pro\n\nA 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.\n\n## Overview\n\nA 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).\n\n## When to use\n\n- Offline-capable web apps (see also pwa-patterns).\n- Caching strategies for assets and API responses.\n- Background sync for queued mutations.\n- Push notification handling.\n- Advanced prefetching\u002Fprerendering strategies.\n\n## Core concepts\n\n- **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).\n- **Scope.** SW controls pages under its registration path. Register at root (`\u002Fsw.js`) for full-site control.\n- **Cache API.** `caches.open('v1')` — programmatic cache storage, separate from HTTP cache. Version cache names; delete old versions on activate.\n- **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.\n- **Precache vs runtime.** Precache the app shell at install (known URLs); cache runtime requests as they happen (API responses, images).\n- **Background Sync.** `sync.register('send-queue')` → SW retries when online — for queued mutations. One-shot; for periodic, Periodic Background Sync (limited support).\n- **Update flow.** Byte-difference check on navigation → new SW installs → waits → activates. UX: notify \"new version available\" → user refreshes, or auto-`skipWaiting` for non-critical apps.\n\n## Practical workflow\n\n**1. Register.**\n```js\nif ('serviceWorker' in navigator) {\n  navigator.serviceWorker.register('\u002Fsw.js').then(reg => {\n    reg.addEventListener('updatefound', () => notifyUpdateAvailable());\n  });\n}\n```\n\n**2. Precache + strategies (vanilla).**\n```js\nconst SHELL = 'shell-v3';\nconst PRECACHE = ['\u002F', '\u002Fapp.css', '\u002Fapp.js', '\u002Foffline.html'];\n\nself.addEventListener('install', (e) => {\n  e.waitUntil(caches.open(SHELL).then(c => c.addAll(PRECACHE)).then(() => self.skipWaiting()));\n});\nself.addEventListener('activate', (e) => {\n  e.waitUntil(caches.keys().then(keys =>\n    Promise.all(keys.filter(k => k !== SHELL).map(k => caches.delete(k)))\n  ).then(() => self.clients.claim()));\n});\nself.addEventListener('fetch', (e) => {\n  const { request } = e;\n  if (request.url.includes('\u002Fapi\u002F')) {\n    e.respondWith(networkFirst(request, 'api-v1'));       \u002F\u002F fresh data, offline fallback\n  } else if (request.destination === 'image') {\n    e.respondWith(cacheFirst(request, 'images-v1'));      \u002F\u002F immutable-ish assets\n  } else {\n    e.respondWith(staleWhileRevalidate(request, SHELL));  \u002F\u002F shell + pages\n  }\n});\n```\n(Or use Workbox — recommended over hand-rolling for production.)\n\n**3. Offline fallback.** Navigation requests failing → serve cached `\u002Foffline.html`. API failing → serve cached response with a flag, or a structured offline error the app handles.\n\n**4. Background sync for mutations.**\n```js\n\u002F\u002F page: queue failed POSTs in IndexedDB, then\nnavigator.serviceWorker.ready.then(reg => reg.sync.register('outbox'));\n\u002F\u002F sw.js: self.addEventListener('sync', e => { if (e.tag === 'outbox') e.waitUntil(flushOutbox()); });\n```\n\n**5. Update UX.** `updatefound` → show \"Update available — refresh\" snackbar → on click, `registration.waiting.postMessage({ type: 'SKIP_WAITING' })` → `controllerchange` → `location.reload()`.\n\n## Common pitfalls\n\n- **Caching the SW file itself.** If `\u002Fsw.js` is cached with a long TTL, updates never arrive. Serve it `Cache-Control: no-cache` (revalidate every time).\n- **Over-aggressive precaching.** Precaching everything = slow install, wasted bandwidth. Precache the shell; runtime-cache the rest.\n- **Stale-forever bugs.** Cache-first on HTML\u002FAPI without versioning = users stuck on ancient content. Version caches; prefer SWR\u002Fnetwork-first for HTML.\n- **Update races.** `skipWaiting` mid-session can break in-flight app state (old page, new cached assets). For complex apps, prompt the user instead of forcing.\n- **Opaque responses.** Cross-origin `no-cors` responses are opaque — cacheable but inscrutable (can't check status). Prefer CORS-enabled endpoints.\n- **Quotas.** Cache + IndexedDB share origin storage (browser-managed, evictable). Don't treat it as infinite; handle `QuotaExceededError`.\n- **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\".\n- **Scope mistakes.** Registering `\u002Fapp\u002Fsw.js` controls only `\u002Fapp\u002F*`. Root registration for site-wide control.\n- **Untested offline.** \"Works offline\" claimed, never tested. DevTools offline mode + real airplane-mode tests on device.\n","# Service Worker Pro\n\nA 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.\n\n## Overview\n\nA 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).\n\n## When to use\n\n- Offline-capable web apps (see also pwa-patterns).\n- Caching strategies for assets and API responses.\n- Background sync for queued mutations.\n- Push notification handling.\n- Advanced prefetching\u002Fprerendering strategies.\n\n## Core concepts\n\n- **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).\n- **Scope.** SW controls pages under its registration path. Register at root (`\u002Fsw.js`) for full-site control.\n- **Cache API.** `caches.open('v1')` — programmatic cache storage, separate from HTTP cache. Version cache names; delete old versions on activate.\n- **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.\n- **Precache vs runtime.** Precache the app shell at install (known URLs); cache runtime requests as they happen (API responses, images).\n- **Background Sync.** `sync.register('send-queue')` → SW retries when online — for queued mutations. One-shot; for periodic, Periodic Background Sync (limited support).\n- **Update flow.** Byte-difference check on navigation → new SW installs → waits → activates. UX: notify \"new version available\" → user refreshes, or auto-`skipWaiting` for non-critical apps.\n\n## Practical workflow\n\n**1. Register.**\n```js\nif ('serviceWorker' in navigator) {\n  navigator.serviceWorker.register('\u002Fsw.js').then(reg => {\n    reg.addEventListener('updatefound', () => notifyUpdateAvailable());\n  });\n}\n```\n\n**2. Precache + strategies (vanilla).**\n```js\nconst SHELL = 'shell-v3';\nconst PRECACHE = ['\u002F', '\u002Fapp.css', '\u002Fapp.js', '\u002Foffline.html'];\n\nself.addEventListener('install', (e) => {\n  e.waitUntil(caches.open(SHELL).then(c => c.addAll(PRECACHE)).then(() => self.skipWaiting()));\n});\nself.addEventListener('activate', (e) => {\n  e.waitUntil(caches.keys().then(keys =>\n    Promise.all(keys.filter(k => k !== SHELL).map(k => caches.delete(k)))\n  ).then(() => self.clients.claim()));\n});\nself.addEventListener('fetch', (e) => {\n  const { request } = e;\n  if (request.url.includes('\u002Fapi\u002F')) {\n    e.respondWith(networkFirst(request, 'api-v1'));       \u002F\u002F fresh data, offline fallback\n  } else if (request.destination === 'image') {\n    e.respondWith(cacheFirst(request, 'images-v1'));      \u002F\u002F immutable-ish assets\n  } else {\n    e.respondWith(staleWhileRevalidate(request, SHELL));  \u002F\u002F shell + pages\n  }\n});\n```\n(Or use Workbox — recommended over hand-rolling for production.)\n\n**3. Offline fallback.** Navigation requests failing → serve cached `\u002Foffline.html`. API failing → serve cached response with a flag, or a structured offline error the app handles.\n\n**4. Background sync for mutations.**\n```js\n\u002F\u002F page: queue failed POSTs in IndexedDB, then\nnavigator.serviceWorker.ready.then(reg => reg.sync.register('outbox'));\n\u002F\u002F sw.js: self.addEventListener('sync', e => { if (e.tag === 'outbox') e.waitUntil(flushOutbox()); });\n```\n\n**5. Update UX.** `updatefound` → show \"Update available — refresh\" snackbar → on click, `registration.waiting.postMessage({ type: 'SKIP_WAITING' })` → `controllerchange` → `location.reload()`.\n\n## Common pitfalls\n\n- **Caching the SW file itself.** If `\u002Fsw.js` is cached with a long TTL, updates never arrive. Serve it `Cache-Control: no-cache` (revalidate every time).\n- **Over-aggressive precaching.** Precaching everything = slow install, wasted bandwidth. Precache the shell; runtime-cache the rest.\n- **Stale-forever bugs.** Cache-first on HTML\u002FAPI without versioning = users stuck on ancient content. Version caches; prefer SWR\u002Fnetwork-first for HTML.\n- **Update races.** `skipWaiting` mid-session can break in-flight app state (old page, new cached assets). For complex apps, prompt the user instead of forcing.\n- **Opaque responses.** Cross-origin `no-cors` responses are opaque — cacheable but inscrutable (can't check status). Prefer CORS-enabled endpoints.\n- **Quotas.** Cache + IndexedDB share origin storage (browser-managed, evictable). Don't treat it as infinite; handle `QuotaExceededError`.\n- **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\".\n- **Scope mistakes.** Registering `\u002Fapp\u002Fsw.js` controls only `\u002Fapp\u002F*`. Root registration for site-wide control.\n- **Untested offline.** \"Works offline\" claimed, never tested. DevTools offline mode + real airplane-mode tests on device.\n",{},"main","af388a77c2fe5e0b4fd879cca4300a0ffa9a6579","skills\u002Fams-service-worker-pro",1,"https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis","https:\u002F\u002Fgithub.com\u002FTanNhatCMS","https:\u002F\u002Fmrkiet.name.vn","2026-11-07 14:23:08",{"source":7,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add TanNhatCMS\u002Fjarvis --skill ams-service-worker-pro",{"tool":37,"command":38},"bunx","bunx skills add TanNhatCMS\u002Fjarvis --skill ams-service-worker-pro",{"tool":40,"command":41},"pnpm","pnpm dlx skills add TanNhatCMS\u002Fjarvis --skill ams-service-worker-pro","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fams-service-worker-pro\u002FSKILL.md",true,[],[46,53,61,68,75,82],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":18},"01M7EWYJR0J8DARY7E59Z6Y9MV","web-scrape","Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open\u002Ffetch fails on JS-heavy pages, or when you need clean markdown\u002Fstructured extraction from a site. Requires FIRECRAWL_API_KEY.","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fweb-scrape\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":57,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":18},"01M7EWYBN5P6F2AJG3FR24T9BP","design-taste-frontend","tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML\u002FCSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, \"AI-made\", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Ftaste-design\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Ftaste-design\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":18},"01M7EWY8FQFNQ2GB7NZZWGSSDX","test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-tdd\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":18},"01M7EWY5SHBFRH1HDHVWM9K7TV","systematic-debugging","Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-debugging\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":18},"01M7EWY3NM0Z0JAKS7HDZ24K66","requesting-code-review","Use when completing tasks, implementing major features, or before merging to verify work meets requirements","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-code-review\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":18},"01M7EWY0WRMWX4M9ZFY0WKC593","brainstorming","You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-brainstorming\u002FSKILL.md",[],[]]