[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CCFFYVWP3PHH82PV8R9BFE":3,"skill-same:01M7CCFFYVWP3PHH82PV8R9BFE":61},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":38,"commitSha":39,"skillDirectory":40,"forksCount":41,"repositoryHtmlUrl":42,"repositoryHomepageUrl":43,"ownerHtmlUrl":44,"ownerBlogUrl":6,"ownerDescription":45,"updatedAt":46,"install":47,"resources":60},"01M7CCFFYVWP3PHH82PV8R9BFE","progressive-web-app",null,"Build Progressive Web Apps (PWAs) with offline support, installability, and caching strategies. Trigger whenever the user mentions PWA, service workers, web app manifests, Workbox, 'add to home screen', or wants their web app to work offline, feel native, or be installable.","YYC-Cube\u002FYYC3-Knowledge-Base","YYC-Cube","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235006543?v=4","01M79J2PH4SWD2X0825X6PN748","yyc3","01M79J2PHVK3F6ZBYT8K2SCZCW",1,"MIT","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Skills-技能包\u002FYYC3-Skills-技能包-antigravity-awesome-skills\u002Fplugins\u002Fantigravity-awesome-skills\u002Fskills\u002Fprogressive-web-app\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: progressive-web-app\ndescription: \"Build Progressive Web Apps (PWAs) with offline support, installability, and caching strategies. Trigger whenever the user mentions PWA, service workers, web app manifests, Workbox, 'add to home screen', or wants their web app to work offline, feel native, or be installable.\"\nrisk: safe\nsource: community\ndate_added: \"2026-03-17\"\ntags: [pwa, web-dev, service-worker, frontend, offline, caching]\ntools: [gemini, cursor, claude]\n---\n\n# Progressive Web Apps (PWAs)\n\n## Overview\n\nA Progressive Web App is a web application that uses modern browser capabilities to deliver a fast, reliable, and installable experience — even on unreliable networks. The three required pillars are:\n\n1. **HTTPS** — Required in production for service workers to register (localhost is exempt for development).\n2. **Web App Manifest** (`manifest.json`) — Makes the app installable and defines its appearance on device home screens.\n3. **Service Worker** (`sw.js`) — A background script that intercepts network requests, manages caches, and enables offline functionality.\n\n## When to Use This Skill\n\n- Use when the user wants their web app to work offline or on unreliable networks.\n- Use when building a mobile-first web project where users should be able to install the app to their home screen.\n- Use when the user asks about caching strategies, service workers, or improving web app performance and resilience.\n- Use when the user mentions Workbox, web app manifests, background sync, or push notifications for the web.\n- Use when the user asks \"can my website be installed like an app?\" or \"how do I make my site work offline?\" — even if they don't use the word PWA.\n\n## Deliverables Checklist\n\nEvery PWA implementation must include these files at minimum:\n\n- [ ] `index.html` — Links manifest, registers service worker\n- [ ] `manifest.json` — Full app metadata and icon set\n- [ ] `sw.js` — Service worker with install, activate, and fetch handlers\n- [ ] `app.js` — Main app logic with SW registration and install prompt handling\n- [ ] `offline.html` — Fallback page shown when navigation fails offline (required — missing file will cause install to fail)\n\n---\n\n## Step 1: Web App Manifest (`manifest.json`)\n\nDefines how the app appears when installed. Must be linked from `\u003Chead>` via `\u003Clink rel=\"manifest\">`.\n\n```json\n{\n  \"name\": \"My Awesome PWA\",\n  \"short_name\": \"MyPWA\",\n  \"description\": \"A fast, offline-capable Progressive Web App.\",\n  \"start_url\": \"\u002F\",\n  \"scope\": \"\u002F\",\n  \"display\": \"standalone\",\n  \"orientation\": \"portrait-primary\",\n  \"background_color\": \"#ffffff\",\n  \"theme_color\": \"#0055ff\",\n  \"icons\": [\n    {\n      \"src\": \"\u002Fassets\u002Ficons\u002Ficon-192x192.png\",\n      \"sizes\": \"192x192\",\n      \"type\": \"image\u002Fpng\",\n      \"purpose\": \"any maskable\"\n    },\n    {\n      \"src\": \"\u002Fassets\u002Ficons\u002Ficon-512x512.png\",\n      \"sizes\": \"512x512\",\n      \"type\": \"image\u002Fpng\",\n      \"purpose\": \"any maskable\"\n    }\n  ],\n  \"screenshots\": [\n    {\n      \"src\": \"\u002Fassets\u002Fscreenshots\u002Fdesktop.png\",\n      \"sizes\": \"1280x720\",\n      \"type\": \"image\u002Fpng\",\n      \"form_factor\": \"wide\"\n    }\n  ]\n}\n```\n\n**Key fields:**\n- `display`: `standalone` hides browser UI; `minimal-ui` shows minimal controls; `browser` is standard tab.\n- `purpose: \"maskable\"` on icons enables adaptive icons on Android (safe zone matters — keep content in center 80%).\n- `screenshots` is optional but required for Chrome's enhanced install dialog on desktop.\n\n---\n\n## Step 2: HTML Shell (`index.html`)\n\n```html\n\u003C!DOCTYPE html>\n\u003Chtml lang=\"en\">\n\u003Chead>\n  \u003Cmeta charset=\"UTF-8\">\n  \u003Cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  \u003Ctitle>My Awesome PWA\u003C\u002Ftitle>\n\n  \u003C!-- PWA manifest -->\n  \u003Clink rel=\"manifest\" href=\"\u002Fmanifest.json\">\n\n  \u003C!-- Theme color for browser chrome -->\n  \u003Cmeta name=\"theme-color\" content=\"#0055ff\">\n\n  \u003C!-- iOS-specific (Safari doesn't fully use manifest) -->\n  \u003Cmeta name=\"apple-mobile-web-app-capable\" content=\"yes\">\n  \u003Cmeta name=\"apple-mobile-web-app-status-bar-style\" content=\"default\">\n  \u003Cmeta name=\"apple-mobile-web-app-title\" content=\"MyPWA\">\n  \u003Clink rel=\"apple-touch-icon\" href=\"\u002Fassets\u002Ficons\u002Ficon-192x192.png\">\n\n  \u003Clink rel=\"stylesheet\" href=\"\u002Fstyles.css\">\n\u003C\u002Fhead>\n\u003Cbody>\n  \u003Cdiv id=\"app\">\n    \u003Cheader>\u003Ch1>My PWA\u003C\u002Fh1>\u003C\u002Fheader>\n    \u003Cmain id=\"content\">Loading...\u003C\u002Fmain>\n    \u003C!-- Optional: install button, hidden by default -->\n    \u003Cbutton id=\"install-btn\" hidden>Install App\u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cscript src=\"\u002Fapp.js\">\u003C\u002Fscript>\n\u003C\u002Fbody>\n\u003C\u002Fhtml>\n```\n\n---\n\n## Step 3: Service Worker Registration & Install Prompt (`app.js`)\n\n```javascript\n\u002F\u002F ─── Service Worker Registration ───────────────────────────────────────────\nif ('serviceWorker' in navigator) {\n  window.addEventListener('load', async () => {\n    try {\n      const registration = await navigator.serviceWorker.register('\u002Fsw.js');\n      console.log('[App] SW registered, scope:', registration.scope);\n    } catch (err) {\n      console.error('[App] SW registration failed:', err);\n    }\n  });\n}\n\n\u002F\u002F ─── Install Prompt (Add to Home Screen) ───────────────────────────────────\nlet deferredPrompt;\nconst installBtn = document.getElementById('install-btn'); \u002F\u002F may be null if omitted\n\n\u002F\u002F Capture the browser's install prompt — it fires before the browser's own UI\nwindow.addEventListener('beforeinstallprompt', (e) => {\n  e.preventDefault(); \u002F\u002F Stop automatic mini-infobar on mobile\n  deferredPrompt = e;\n  if (installBtn) installBtn.hidden = false; \u002F\u002F Show your custom install button\n});\n\nif (installBtn) {\n  installBtn.addEventListener('click', async () => {\n    if (!deferredPrompt) return;\n    deferredPrompt.prompt();\n    const { outcome } = await deferredPrompt.userChoice;\n    console.log('[App] Install outcome:', outcome);\n    deferredPrompt = null;\n    installBtn.hidden = true;\n  });\n}\n\u002F\u002F Fires when the app is installed (via browser or your button)\nwindow.addEventListener('appinstalled', () => {\n  console.log('[App] PWA installed successfully');\n  installBtn.hidden = true;\n});\n```\n\n---\n\n## Step 4: Service Worker (`sw.js`)\n\n### Cache Versioning (critical — always increment on deploy)\n\n```javascript\nconst CACHE_VERSION = 'v1';\nconst STATIC_CACHE = `static-${CACHE_VERSION}`;\nconst DYNAMIC_CACHE = `dynamic-${CACHE_VERSION}`;\n\n\u002F\u002F Files to pre-cache during install (the \"App Shell\")\nconst APP_SHELL = [\n  '\u002F',\n  '\u002Findex.html',\n  '\u002Fstyles.css',\n  '\u002Fapp.js',\n  '\u002Fassets\u002Ficons\u002Ficon-192x192.png',\n  '\u002Foffline.html', \u002F\u002F Fallback page shown when network is unavailable\n];\n```\n\n### Install — Pre-cache the App Shell\n\n```javascript\nself.addEventListener('install', (event) => {\n  console.log('[SW] Installing...');\n  event.waitUntil(\n    caches.open(STATIC_CACHE).then((cache) => {\n      console.log('[SW] Pre-caching app shell');\n      return cache.addAll(APP_SHELL);\n    })\n  );\n  \u002F\u002F Activate immediately without waiting for old SW to die\n  self.skipWaiting();\n});\n```\n\n### Activate — Clean Up Old Caches\n\n```javascript\nself.addEventListener('activate', (event) => {\n  console.log('[SW] Activating...');\n  event.waitUntil(\n    caches.keys().then((cacheNames) => {\n      return Promise.all(\n        cacheNames\n          .filter((name) => name !== STATIC_CACHE && name !== DYNAMIC_CACHE)\n          .map((name) => {\n            console.log('[SW] Deleting old cache:', name);\n            return caches.delete(name);\n          })\n      );\n    })\n  );\n  \u002F\u002F Take control of all pages immediately\n  self.clients.claim();\n});\n```\n\n### Fetch — Caching Strategies\n\nChoose the right strategy per resource type:\n\n```javascript\nself.addEventListener('fetch', (event) => {\n  const { request } = event;\n  const url = new URL(request.url);\n\n  \u002F\u002F Only handle GET requests from our own origin\n  if (request.method !== 'GET' || url.origin !== location.origin) return;\n\n  \u002F\u002F Strategy A: Cache-First (for static assets — fast, tolerates stale)\n  if (url.pathname.match(\u002F\\.(css|js|png|jpg|svg|woff2)$\u002F)) {\n    event.respondWith(cacheFirst(request));\n    return;\n  }\n\n  \u002F\u002F Strategy B: Network-First (for HTML pages — fresh, falls back to cache)\n  if (request.headers.get('Accept')?.includes('text\u002Fhtml')) {\n    event.respondWith(networkFirst(request));\n    return;\n  }\n\n  \u002F\u002F Strategy C: Stale-While-Revalidate (for API data — fast and eventually fresh)\n  if (url.pathname.startsWith('\u002Fapi\u002F')) {\n    event.respondWith(staleWhileRevalidate(request));\n    return;\n  }\n});\n\n\u002F\u002F ─── Strategy Implementations ──────────────────────────────────────────────\n\nasync function cacheFirst(request) {\n  const cached = await caches.match(request);\n  if (cached) return cached;\n  try {\n    const response = await fetch(request);\n    const cache = await caches.open(STATIC_CACHE);\n    cache.put(request, response.clone());\n    return response;\n  } catch {\n    \u002F\u002F Nothing useful to fall back to for assets\n    return new Response('Asset unavailable offline', { status: 503 });\n  }\n}\n\nasync function networkFirst(request) {\n  try {\n    const response = await fetch(request);\n    const cache = await caches.open(DYNAMIC_CACHE);\n    cache.put(request, response.clone());\n    return response;\n  } catch {\n    const cached = await caches.match(request);\n    return cached || caches.match('\u002Foffline.html');\n  }\n}\n\nasync function staleWhileRevalidate(request) {\n  const cache = await caches.open(DYNAMIC_CACHE);\n  const cached = await cache.match(request);\n  const fetchPromise = fetch(request).then((response) => {\n    cache.put(request, response.clone());\n    return response;\n  });\n  return cached || fetchPromise;\n}\n```\n\n---\n\n## Edge Cases & Platform Notes\n\n### iOS \u002F Safari Quirks\n- Safari supports manifests and service workers but **does not support `beforeinstallprompt`** — users must install via the Share → \"Add to Home Screen\" menu manually.\n- Use the `apple-mobile-web-app-*` meta tags (shown in `index.html` above) for proper iOS integration.\n- Safari may clear service worker caches after ~7 days of inactivity (Intelligent Tracking Prevention).\n\n### HTTPS Requirement\n- Service workers only register on `https:\u002F\u002F` origins. `http:\u002F\u002Flocalhost` is the only exception for development.\n- Use a tool like `mkcert` or `ngrok` if you need HTTPS locally with a custom hostname.\n\n### Cache-Busting on Deploy\n- Always increment `CACHE_VERSION` in `sw.js` when deploying new assets. This ensures activate clears old caches and users get fresh files.\n- A common pattern is to inject the version automatically via your build tool (e.g., Vite, Webpack).\n\n### Opaque Responses (cross-origin requests)\n- Requests to external origins (e.g., CDN fonts, third-party APIs) return \"opaque\" responses that cannot be inspected. Cache them with caution — a failed opaque response still gets a `200` status.\n- Prefer `staleWhileRevalidate` for cross-origin resources, or use a library like Workbox which handles this safely.\n\n---\n\n## Workbox (Optional: Production Shortcut)\n\nFor production apps, consider [Workbox](https:\u002F\u002Fdeveloper.chrome.com\u002Fdocs\u002Fworkbox) (Google's PWA library) instead of hand-rolling strategies. It handles edge cases, cache expiry, and versioning automatically.\n\n```javascript\n\u002F\u002F With Workbox (via CDN for simplicity — use npm + bundler in production)\nimportScripts('https:\u002F\u002Fstorage.googleapis.com\u002Fworkbox-cdn\u002Freleases\u002F7.0.0\u002Fworkbox-sw.js');\n\nconst { registerRoute } = workbox.routing;\nconst { CacheFirst, NetworkFirst, StaleWhileRevalidate } = workbox.strategies;\nconst { precacheAndRoute } = workbox.precaching;\n\nprecacheAndRoute(self.__WB_MANIFEST || []); \u002F\u002F Injected by build plugin\n\nregisterRoute(({ request }) => request.destination === 'image', new CacheFirst());\nregisterRoute(({ request }) => request.mode === 'navigate', new NetworkFirst());\nregisterRoute(({ request }) => request.destination === 'script', new StaleWhileRevalidate());\n```\n\n---\n\n## Checklist Before Shipping\n\n- [ ] Site is served over HTTPS\n- [ ] `manifest.json` has `name`, `short_name`, `start_url`, `display`, `icons` (192 + 512)\n- [ ] Icons have `purpose: \"any maskable\"`\n- [ ] `sw.js` registers without errors in DevTools → Application → Service Workers\n- [ ] App shell loads from cache when network is throttled to \"Offline\" in DevTools\n- [ ] `offline.html` fallback is cached and served when navigation fails offline\n- [ ] Lighthouse PWA audit passes (Chrome DevTools → Lighthouse tab)\n- [ ] Tested on iOS Safari (manual install flow) and Android Chrome (install prompt)\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","# Progressive Web Apps (PWAs)\n\n## Overview\n\nA Progressive Web App is a web application that uses modern browser capabilities to deliver a fast, reliable, and installable experience — even on unreliable networks. The three required pillars are:\n\n1. **HTTPS** — Required in production for service workers to register (localhost is exempt for development).\n2. **Web App Manifest** (`manifest.json`) — Makes the app installable and defines its appearance on device home screens.\n3. **Service Worker** (`sw.js`) — A background script that intercepts network requests, manages caches, and enables offline functionality.\n\n## When to Use This Skill\n\n- Use when the user wants their web app to work offline or on unreliable networks.\n- Use when building a mobile-first web project where users should be able to install the app to their home screen.\n- Use when the user asks about caching strategies, service workers, or improving web app performance and resilience.\n- Use when the user mentions Workbox, web app manifests, background sync, or push notifications for the web.\n- Use when the user asks \"can my website be installed like an app?\" or \"how do I make my site work offline?\" — even if they don't use the word PWA.\n\n## Deliverables Checklist\n\nEvery PWA implementation must include these files at minimum:\n\n- [ ] `index.html` — Links manifest, registers service worker\n- [ ] `manifest.json` — Full app metadata and icon set\n- [ ] `sw.js` — Service worker with install, activate, and fetch handlers\n- [ ] `app.js` — Main app logic with SW registration and install prompt handling\n- [ ] `offline.html` — Fallback page shown when navigation fails offline (required — missing file will cause install to fail)\n\n---\n\n## Step 1: Web App Manifest (`manifest.json`)\n\nDefines how the app appears when installed. Must be linked from `\u003Chead>` via `\u003Clink rel=\"manifest\">`.\n\n```json\n{\n  \"name\": \"My Awesome PWA\",\n  \"short_name\": \"MyPWA\",\n  \"description\": \"A fast, offline-capable Progressive Web App.\",\n  \"start_url\": \"\u002F\",\n  \"scope\": \"\u002F\",\n  \"display\": \"standalone\",\n  \"orientation\": \"portrait-primary\",\n  \"background_color\": \"#ffffff\",\n  \"theme_color\": \"#0055ff\",\n  \"icons\": [\n    {\n      \"src\": \"\u002Fassets\u002Ficons\u002Ficon-192x192.png\",\n      \"sizes\": \"192x192\",\n      \"type\": \"image\u002Fpng\",\n      \"purpose\": \"any maskable\"\n    },\n    {\n      \"src\": \"\u002Fassets\u002Ficons\u002Ficon-512x512.png\",\n      \"sizes\": \"512x512\",\n      \"type\": \"image\u002Fpng\",\n      \"purpose\": \"any maskable\"\n    }\n  ],\n  \"screenshots\": [\n    {\n      \"src\": \"\u002Fassets\u002Fscreenshots\u002Fdesktop.png\",\n      \"sizes\": \"1280x720\",\n      \"type\": \"image\u002Fpng\",\n      \"form_factor\": \"wide\"\n    }\n  ]\n}\n```\n\n**Key fields:**\n- `display`: `standalone` hides browser UI; `minimal-ui` shows minimal controls; `browser` is standard tab.\n- `purpose: \"maskable\"` on icons enables adaptive icons on Android (safe zone matters — keep content in center 80%).\n- `screenshots` is optional but required for Chrome's enhanced install dialog on desktop.\n\n---\n\n## Step 2: HTML Shell (`index.html`)\n\n```html\n\u003C!DOCTYPE html>\n\u003Chtml lang=\"en\">\n\u003Chead>\n  \u003Cmeta charset=\"UTF-8\">\n  \u003Cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  \u003Ctitle>My Awesome PWA\u003C\u002Ftitle>\n\n  \u003C!-- PWA manifest -->\n  \u003Clink rel=\"manifest\" href=\"\u002Fmanifest.json\">\n\n  \u003C!-- Theme color for browser chrome -->\n  \u003Cmeta name=\"theme-color\" content=\"#0055ff\">\n\n  \u003C!-- iOS-specific (Safari doesn't fully use manifest) -->\n  \u003Cmeta name=\"apple-mobile-web-app-capable\" content=\"yes\">\n  \u003Cmeta name=\"apple-mobile-web-app-status-bar-style\" content=\"default\">\n  \u003Cmeta name=\"apple-mobile-web-app-title\" content=\"MyPWA\">\n  \u003Clink rel=\"apple-touch-icon\" href=\"\u002Fassets\u002Ficons\u002Ficon-192x192.png\">\n\n  \u003Clink rel=\"stylesheet\" href=\"\u002Fstyles.css\">\n\u003C\u002Fhead>\n\u003Cbody>\n  \u003Cdiv id=\"app\">\n    \u003Cheader>\u003Ch1>My PWA\u003C\u002Fh1>\u003C\u002Fheader>\n    \u003Cmain id=\"content\">Loading...\u003C\u002Fmain>\n    \u003C!-- Optional: install button, hidden by default -->\n    \u003Cbutton id=\"install-btn\" hidden>Install App\u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cscript src=\"\u002Fapp.js\">\u003C\u002Fscript>\n\u003C\u002Fbody>\n\u003C\u002Fhtml>\n```\n\n---\n\n## Step 3: Service Worker Registration & Install Prompt (`app.js`)\n\n```javascript\n\u002F\u002F ─── Service Worker Registration ───────────────────────────────────────────\nif ('serviceWorker' in navigator) {\n  window.addEventListener('load', async () => {\n    try {\n      const registration = await navigator.serviceWorker.register('\u002Fsw.js');\n      console.log('[App] SW registered, scope:', registration.scope);\n    } catch (err) {\n      console.error('[App] SW registration failed:', err);\n    }\n  });\n}\n\n\u002F\u002F ─── Install Prompt (Add to Home Screen) ───────────────────────────────────\nlet deferredPrompt;\nconst installBtn = document.getElementById('install-btn'); \u002F\u002F may be null if omitted\n\n\u002F\u002F Capture the browser's install prompt — it fires before the browser's own UI\nwindow.addEventListener('beforeinstallprompt', (e) => {\n  e.preventDefault(); \u002F\u002F Stop automatic mini-infobar on mobile\n  deferredPrompt = e;\n  if (installBtn) installBtn.hidden = false; \u002F\u002F Show your custom install button\n});\n\nif (installBtn) {\n  installBtn.addEventListener('click', async () => {\n    if (!deferredPrompt) return;\n    deferredPrompt.prompt();\n    const { outcome } = await deferredPrompt.userChoice;\n    console.log('[App] Install outcome:', outcome);\n    deferredPrompt = null;\n    installBtn.hidden = true;\n  });\n}\n\u002F\u002F Fires when the app is installed (via browser or your button)\nwindow.addEventListener('appinstalled', () => {\n  console.log('[App] PWA installed successfully');\n  installBtn.hidden = true;\n});\n```\n\n---\n\n## Step 4: Service Worker (`sw.js`)\n\n### Cache Versioning (critical — always increment on deploy)\n\n```javascript\nconst CACHE_VERSION = 'v1';\nconst STATIC_CACHE = `static-${CACHE_VERSION}`;\nconst DYNAMIC_CACHE = `dynamic-${CACHE_VERSION}`;\n\n\u002F\u002F Files to pre-cache during install (the \"App Shell\")\nconst APP_SHELL = [\n  '\u002F',\n  '\u002Findex.html',\n  '\u002Fstyles.css',\n  '\u002Fapp.js',\n  '\u002Fassets\u002Ficons\u002Ficon-192x192.png',\n  '\u002Foffline.html', \u002F\u002F Fallback page shown when network is unavailable\n];\n```\n\n### Install — Pre-cache the App Shell\n\n```javascript\nself.addEventListener('install', (event) => {\n  console.log('[SW] Installing...');\n  event.waitUntil(\n    caches.open(STATIC_CACHE).then((cache) => {\n      console.log('[SW] Pre-caching app shell');\n      return cache.addAll(APP_SHELL);\n    })\n  );\n  \u002F\u002F Activate immediately without waiting for old SW to die\n  self.skipWaiting();\n});\n```\n\n### Activate — Clean Up Old Caches\n\n```javascript\nself.addEventListener('activate', (event) => {\n  console.log('[SW] Activating...');\n  event.waitUntil(\n    caches.keys().then((cacheNames) => {\n      return Promise.all(\n        cacheNames\n          .filter((name) => name !== STATIC_CACHE && name !== DYNAMIC_CACHE)\n          .map((name) => {\n            console.log('[SW] Deleting old cache:', name);\n            return caches.delete(name);\n          })\n      );\n    })\n  );\n  \u002F\u002F Take control of all pages immediately\n  self.clients.claim();\n});\n```\n\n### Fetch — Caching Strategies\n\nChoose the right strategy per resource type:\n\n```javascript\nself.addEventListener('fetch', (event) => {\n  const { request } = event;\n  const url = new URL(request.url);\n\n  \u002F\u002F Only handle GET requests from our own origin\n  if (request.method !== 'GET' || url.origin !== location.origin) return;\n\n  \u002F\u002F Strategy A: Cache-First (for static assets — fast, tolerates stale)\n  if (url.pathname.match(\u002F\\.(css|js|png|jpg|svg|woff2)$\u002F)) {\n    event.respondWith(cacheFirst(request));\n    return;\n  }\n\n  \u002F\u002F Strategy B: Network-First (for HTML pages — fresh, falls back to cache)\n  if (request.headers.get('Accept')?.includes('text\u002Fhtml')) {\n    event.respondWith(networkFirst(request));\n    return;\n  }\n\n  \u002F\u002F Strategy C: Stale-While-Revalidate (for API data — fast and eventually fresh)\n  if (url.pathname.startsWith('\u002Fapi\u002F')) {\n    event.respondWith(staleWhileRevalidate(request));\n    return;\n  }\n});\n\n\u002F\u002F ─── Strategy Implementations ──────────────────────────────────────────────\n\nasync function cacheFirst(request) {\n  const cached = await caches.match(request);\n  if (cached) return cached;\n  try {\n    const response = await fetch(request);\n    const cache = await caches.open(STATIC_CACHE);\n    cache.put(request, response.clone());\n    return response;\n  } catch {\n    \u002F\u002F Nothing useful to fall back to for assets\n    return new Response('Asset unavailable offline', { status: 503 });\n  }\n}\n\nasync function networkFirst(request) {\n  try {\n    const response = await fetch(request);\n    const cache = await caches.open(DYNAMIC_CACHE);\n    cache.put(request, response.clone());\n    return response;\n  } catch {\n    const cached = await caches.match(request);\n    return cached || caches.match('\u002Foffline.html');\n  }\n}\n\nasync function staleWhileRevalidate(request) {\n  const cache = await caches.open(DYNAMIC_CACHE);\n  const cached = await cache.match(request);\n  const fetchPromise = fetch(request).then((response) => {\n    cache.put(request, response.clone());\n    return response;\n  });\n  return cached || fetchPromise;\n}\n```\n\n---\n\n## Edge Cases & Platform Notes\n\n### iOS \u002F Safari Quirks\n- Safari supports manifests and service workers but **does not support `beforeinstallprompt`** — users must install via the Share → \"Add to Home Screen\" menu manually.\n- Use the `apple-mobile-web-app-*` meta tags (shown in `index.html` above) for proper iOS integration.\n- Safari may clear service worker caches after ~7 days of inactivity (Intelligent Tracking Prevention).\n\n### HTTPS Requirement\n- Service workers only register on `https:\u002F\u002F` origins. `http:\u002F\u002Flocalhost` is the only exception for development.\n- Use a tool like `mkcert` or `ngrok` if you need HTTPS locally with a custom hostname.\n\n### Cache-Busting on Deploy\n- Always increment `CACHE_VERSION` in `sw.js` when deploying new assets. This ensures activate clears old caches and users get fresh files.\n- A common pattern is to inject the version automatically via your build tool (e.g., Vite, Webpack).\n\n### Opaque Responses (cross-origin requests)\n- Requests to external origins (e.g., CDN fonts, third-party APIs) return \"opaque\" responses that cannot be inspected. Cache them with caution — a failed opaque response still gets a `200` status.\n- Prefer `staleWhileRevalidate` for cross-origin resources, or use a library like Workbox which handles this safely.\n\n---\n\n## Workbox (Optional: Production Shortcut)\n\nFor production apps, consider [Workbox](https:\u002F\u002Fdeveloper.chrome.com\u002Fdocs\u002Fworkbox) (Google's PWA library) instead of hand-rolling strategies. It handles edge cases, cache expiry, and versioning automatically.\n\n```javascript\n\u002F\u002F With Workbox (via CDN for simplicity — use npm + bundler in production)\nimportScripts('https:\u002F\u002Fstorage.googleapis.com\u002Fworkbox-cdn\u002Freleases\u002F7.0.0\u002Fworkbox-sw.js');\n\nconst { registerRoute } = workbox.routing;\nconst { CacheFirst, NetworkFirst, StaleWhileRevalidate } = workbox.strategies;\nconst { precacheAndRoute } = workbox.precaching;\n\nprecacheAndRoute(self.__WB_MANIFEST || []); \u002F\u002F Injected by build plugin\n\nregisterRoute(({ request }) => request.destination === 'image', new CacheFirst());\nregisterRoute(({ request }) => request.mode === 'navigate', new NetworkFirst());\nregisterRoute(({ request }) => request.destination === 'script', new StaleWhileRevalidate());\n```\n\n---\n\n## Checklist Before Shipping\n\n- [ ] Site is served over HTTPS\n- [ ] `manifest.json` has `name`, `short_name`, `start_url`, `display`, `icons` (192 + 512)\n- [ ] Icons have `purpose: \"any maskable\"`\n- [ ] `sw.js` registers without errors in DevTools → Application → Service Workers\n- [ ] App shell loads from cache when network is throttled to \"Offline\" in DevTools\n- [ ] `offline.html` fallback is cached and served when navigation fails offline\n- [ ] Lighthouse PWA audit passes (Chrome DevTools → Lighthouse tab)\n- [ ] Tested on iOS Safari (manual install flow) and Android Chrome (install prompt)\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n",{"name":5,"risk":24,"tags":25,"tools":32,"source":36,"date_added":37,"description":7},"safe",[26,27,28,29,30,31],"pwa","web-dev","service-worker","frontend","offline","caching",[33,34,35],"gemini","cursor","claude","community","2026-03-17","main","87afe6ce96220accf50a345dea46784c8c9f210e","YYC3-Skills-技能包\u002FYYC3-Skills-技能包-antigravity-awesome-skills\u002Fplugins\u002Fantigravity-awesome-skills\u002Fskills\u002Fprogressive-web-app",0,"https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base","https:\u002F\u002Fkb.yyc3.top\u002F","https:\u002F\u002Fgithub.com\u002FYYC-Cube","万象归元于云枢 | 深栈智启新纪元","2026-11-10 10:37:32",{"source":8,"skillName":5,"commands":48,"prompt":58,"zipAvailable":59},[49,52,55],{"tool":50,"command":51},"npx","npx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill progressive-web-app",{"tool":53,"command":54},"bunx","bunx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill progressive-web-app",{"tool":56,"command":57},"pnpm","pnpm dlx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill progressive-web-app","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Skills-技能包\u002FYYC3-Skills-技能包-antigravity-awesome-skills\u002Fplugins\u002Fantigravity-awesome-skills\u002Fskills\u002Fprogressive-web-app\u002FSKILL.md",true,[],[62,69,76,83,90,97],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M7CTDWHERCXPQCP0K03A86AS","vercel-sandbox","Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include \"Vercel Sandbox browser\", \"microVM Chrome\", \"agent-browser in sandbox\", \"browser automation on Vercel\", or any task requiring Chrome in a Vercel Sandbox.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fvercel-sandbox\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7CTD8D2BNJY54S65M47HEJA","slack","Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include \"check my Slack\", \"what channels have unreads\", \"send a message to\", \"search Slack for\", \"extract from Slack\", \"find who said\", or any task requiring programmatic Slack interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fslack\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M7CTCSSB8ZP3Q58C3YZDZK1W","electron","Automate Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify, etc.) using agent-browser via Chrome DevTools Protocol. Use when the user needs to interact with an Electron app, automate a desktop app, connect to a running app, control a native app, or test an Electron application. Triggers include \"automate Slack app\", \"control VS Code\", \"interact with Discord app\", \"test this Electron app\", \"connect to desktop app\", or any task requiring automation of a native Electron application.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Felectron\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M7CTCBJY76688V4DCZGWFHGQ","dogfood","Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to \"dogfood\", \"QA\", \"exploratory test\", \"find issues\", \"bug hunt\", \"test this app\u002Fsite\u002Fplatform\", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fdogfood\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M7CTC4H0FFGVEAQR9PA4GA1A","agent-browser","Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to \"open a website\", \"fill out a form\", \"click a button\", \"take a screenshot\", \"scrape data from a page\", \"test this web app\", \"login to a site\", \"automate browser actions\", or any task requiring programmatic web interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fagent-browser\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":19},"01M7CTBKVFYBG78FDSABSDJTTQ","shadcn","Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI, including chat interfaces. Provides project context, component docs, and usage examples. Applies when working with shadcn\u002Fui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for \"shadcn init\", \"create an app with --preset\", \"switch to --preset\", and for building a design system or applying a DESIGN.md or brand spec to shadcn\u002Fui.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-UI-界面组件\u002FYYC3-UI-界面组件-ui\u002Fskills\u002Fshadcn\u002FSKILL.md",[],[]]