Overview
Guides the complete conversion of a web app into a Progressive Web App: creating a Web App Manifest, implementing a service worker with caching strategies (Cache First, Network First, Stale-While-Revalidate), offline fallback page, install prompt handling, and push notification setup using the Push API + VAPID keys.
When to Use This Skill
- The app should feel like a native app (installable from browser).
- Users need to use core features offline (read content, draft forms, view dashboards).
- Adding push notifications for re-engagement.
- The user says "make this a PWA", "add offline support", "installable web app".
Prerequisites
- HTTPS (required for service workers and push in production; localhost works for dev).
- Modern browser support (all current evergreen browsers).
- For push: a push service (Firebase Cloud Messaging, VAPID + web-push library on server).
Steps
Create Web App Manifest (app/manifest.ts or public/manifest.json):
- name, short_name, start_url, display ("standalone"), background_color, theme_color, icons (192x192, 512x512, maskable).
- Screenshots for install prompt (optional but powerful).
Implement Service Worker:
- Lifecycle: install → activate → fetch.
- Caching strategies per asset type:
- App shell (HTML, CSS, JS critical): Cache First or Stale-While-Revalidate.
- API/data: Network First with cache fallback.
- Images: Cache First with long TTL.
- Use Workbox (recommended) or write a small custom SW.
Offline fallback:
- A dedicated offline.html page.
- In fetch handler, return it when network fails for navigation requests.
Install prompt:
- Listen for
beforeinstallprompt.
- Show a custom "Install" button.
- Call
prompt() on user gesture.
- Handle
appinstalled event.
Push notifications:
- Request permission.
- Subscribe to push using VAPID public key.
- Send subscription to your server.
- Server sends push using
web-push library.
- Handle
push event in SW and show Notification.
Next.js specific:
- Use
next-pwa plugin or manual setup with public/sw.js.
- Register SW in a client component or layout.
Output:
- Full manifest.
- Service worker code (or Workbox config).
- React hook or component for install prompt.
- Push subscription example.
- VAPID key generation instructions.
- Testing checklist.
Examples
Complete manifest.ts, a production-ready service worker with multiple strategies, install prompt component, and a minimal push notification flow (client + server) are included.
Edge Cases & Error Handling
- Permission denied for notifications: Graceful UI, never nag.
- SW update: Proper skipWaiting + clients.claim, with update UI prompt.
- Large offline assets: Be selective about what goes in the cache.
- Background sync: For form submissions when offline (using Background Sync API).
Verification
npm run build && npm run start — serve over HTTPS (use serve or Vercel).
- Open in Chrome — "Install" button or + icon in address bar appears.
- Click install — app installs to home screen / apps list.
- Go offline (DevTools → Network → Offline) — core pages still load.
- Trigger a push notification from server — it arrives even when app is closed.
- Lighthouse PWA category = 100.
- Success: App is installable, works offline for key flows, and can receive push.
References
1---2name: pwa-setup3description: Converts a web app to a Progressive Web App with offline support, install prompts, and push notifications. Use when making a web app installable and offline-capable.4license: Apache-2.05compatibility: Claude Code, Codex, Gemini CLI6metadata:7 author: ai-skills8 version: "1.0"9 category: web-development10 tags: pwa, service-worker, manifest, offline, push-notifications, web-app-manifest11---1213## Overview1415Guides the complete conversion of a web app into a Progressive Web App: creating a Web App Manifest, implementing a service worker with caching strategies (Cache First, Network First, Stale-While-Revalidate), offline fallback page, install prompt handling, and push notification setup using the Push API + VAPID keys.1617## When to Use This Skill1819- The app should feel like a native app (installable from browser).20- Users need to use core features offline (read content, draft forms, view dashboards).21- Adding push notifications for re-engagement.22- The user says "make this a PWA", "add offline support", "installable web app".2324## Prerequisites2526- HTTPS (required for service workers and push in production; localhost works for dev).27- Modern browser support (all current evergreen browsers).28- For push: a push service (Firebase Cloud Messaging, VAPID + web-push library on server).2930## Steps31321. **Create Web App Manifest** (`app/manifest.ts` or `public/manifest.json`):33 - name, short_name, start_url, display ("standalone"), background_color, theme_color, icons (192x192, 512x512, maskable).34 - Screenshots for install prompt (optional but powerful).35362. **Implement Service Worker**:37 - Lifecycle: install → activate → fetch.38 - Caching strategies per asset type:39 - App shell (HTML, CSS, JS critical): Cache First or Stale-While-Revalidate.40 - API/data: Network First with cache fallback.41 - Images: Cache First with long TTL.42 - Use Workbox (recommended) or write a small custom SW.43443. **Offline fallback**:45 - A dedicated offline.html page.46 - In fetch handler, return it when network fails for navigation requests.47484. **Install prompt**:49 - Listen for `beforeinstallprompt`.50 - Show a custom "Install" button.51 - Call `prompt()` on user gesture.52 - Handle `appinstalled` event.53545. **Push notifications**:55 - Request permission.56 - Subscribe to push using VAPID public key.57 - Send subscription to your server.58 - Server sends push using `web-push` library.59 - Handle `push` event in SW and show Notification.60616. **Next.js specific**:62 - Use `next-pwa` plugin or manual setup with `public/sw.js`.63 - Register SW in a client component or layout.64657. **Output**:66 - Full manifest.67 - Service worker code (or Workbox config).68 - React hook or component for install prompt.69 - Push subscription example.70 - VAPID key generation instructions.71 - Testing checklist.7273## Examples7475Complete `manifest.ts`, a production-ready service worker with multiple strategies, install prompt component, and a minimal push notification flow (client + server) are included.7677## Edge Cases & Error Handling7879- **Permission denied for notifications**: Graceful UI, never nag.80- **SW update**: Proper skipWaiting + clients.claim, with update UI prompt.81- **Large offline assets**: Be selective about what goes in the cache.82- **Background sync**: For form submissions when offline (using Background Sync API).8384## Verification85861. `npm run build && npm run start` — serve over HTTPS (use `serve` or Vercel).872. Open in Chrome — "Install" button or + icon in address bar appears.883. Click install — app installs to home screen / apps list.894. Go offline (DevTools → Network → Offline) — core pages still load.905. Trigger a push notification from server — it arrives even when app is closed.916. Lighthouse PWA category = 100.927. Success: App is installable, works offline for key flows, and can receive push.9394## References9596- [Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest)97- [Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)98- [Workbox](https://developer.chrome.com/docs/workbox/)99- [Push API + Notifications](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)100- [next-pwa](https://github.com/shadowwalker/next-pwa) or manual setup