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.05---67## Overview89Guides 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.1011## When to Use This Skill1213- The app should feel like a native app (installable from browser).14- Users need to use core features offline (read content, draft forms, view dashboards).15- Adding push notifications for re-engagement.16- The user says "make this a PWA", "add offline support", "installable web app".1718## Prerequisites1920- HTTPS (required for service workers and push in production; localhost works for dev).21- Modern browser support (all current evergreen browsers).22- For push: a push service (Firebase Cloud Messaging, VAPID + web-push library on server).2324## Steps25261. **Create Web App Manifest** (`app/manifest.ts` or `public/manifest.json`):27 - name, short_name, start_url, display ("standalone"), background_color, theme_color, icons (192x192, 512x512, maskable).28 - Screenshots for install prompt (optional but powerful).29302. **Implement Service Worker**:31 - Lifecycle: install → activate → fetch.32 - Caching strategies per asset type:33 - App shell (HTML, CSS, JS critical): Cache First or Stale-While-Revalidate.34 - API/data: Network First with cache fallback.35 - Images: Cache First with long TTL.36 - Use Workbox (recommended) or write a small custom SW.37383. **Offline fallback**:39 - A dedicated offline.html page.40 - In fetch handler, return it when network fails for navigation requests.41424. **Install prompt**:43 - Listen for `beforeinstallprompt`.44 - Show a custom "Install" button.45 - Call `prompt()` on user gesture.46 - Handle `appinstalled` event.47485. **Push notifications**:49 - Request permission.50 - Subscribe to push using VAPID public key.51 - Send subscription to your server.52 - Server sends push using `web-push` library.53 - Handle `push` event in SW and show Notification.54556. **Next.js specific**:56 - Use `next-pwa` plugin or manual setup with `public/sw.js`.57 - Register SW in a client component or layout.58597. **Output**:60 - Full manifest.61 - Service worker code (or Workbox config).62 - React hook or component for install prompt.63 - Push subscription example.64 - VAPID key generation instructions.65 - Testing checklist.6667## Examples6869Complete `manifest.ts`, a production-ready service worker with multiple strategies, install prompt component, and a minimal push notification flow (client + server) are included.7071## Edge Cases & Error Handling7273- **Permission denied for notifications**: Graceful UI, never nag.74- **SW update**: Proper skipWaiting + clients.claim, with update UI prompt.75- **Large offline assets**: Be selective about what goes in the cache.76- **Background sync**: For form submissions when offline (using Background Sync API).7778## Verification79801. `npm run build && npm run start` — serve over HTTPS (use `serve` or Vercel).812. Open in Chrome — "Install" button or + icon in address bar appears.823. Click install — app installs to home screen / apps list.834. Go offline (DevTools → Network → Offline) — core pages still load.845. Trigger a push notification from server — it arrives even when app is closed.856. Lighthouse PWA category = 100.867. Success: App is installable, works offline for key flows, and can receive push.8788## References8990- [Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest)91- [Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)92- [Workbox](https://developer.chrome.com/docs/workbox/)93- [Push API + Notifications](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)94- [next-pwa](https://github.com/shadowwalker/next-pwa) or manual setup