Progressive Web Apps (PWAs)
Overview
A 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:
- HTTPS — Required in production for service workers to register (localhost is exempt for development).
- Web App Manifest (
manifest.json) — Makes the app installable and defines its appearance on device home screens.
- Service Worker (
sw.js) — A background script that intercepts network requests, manages caches, and enables offline functionality.
When to Use This Skill
- Use when the user wants their web app to work offline or on unreliable networks.
- Use when building a mobile-first web project where users should be able to install the app to their home screen.
- Use when the user asks about caching strategies, service workers, or improving web app performance and resilience.
- Use when the user mentions Workbox, web app manifests, background sync, or push notifications for the web.
- 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.
Deliverables Checklist
Every PWA implementation must include these files at minimum:
Step 1: Web App Manifest (manifest.json)
Defines how the app appears when installed. Must be linked from <head> via <link rel="manifest">.
{
"name": "My Awesome PWA",
"short_name": "MyPWA",
"description": "A fast, offline-capable Progressive Web App.",
"start_url": "/",
"scope": "/",
"display": "standalone",
"orientation": "portrait-primary",
"background_color": "#ffffff",
"theme_color": "#0055ff",
"icons": [
{
"src": "/assets/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "/assets/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
],
"screenshots": [
{
"src": "/assets/screenshots/desktop.png",
"sizes": "1280x720",
"type": "image/png",
"form_factor": "wide"
}
]
}
Key fields:
display: standalone hides browser UI; minimal-ui shows minimal controls; browser is standard tab.
purpose: "maskable" on icons enables adaptive icons on Android (safe zone matters — keep content in center 80%).
screenshots is optional but required for Chrome's enhanced install dialog on desktop.
Step 2: HTML Shell (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Awesome PWA</title>
<!-- PWA manifest -->
<link rel="manifest" href="/manifest.json">
<!-- Theme color for browser chrome -->
<meta name="theme-color" content="#0055ff">
<!-- iOS-specific (Safari doesn't fully use manifest) -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="apple-mobile-web-app-title" content="MyPWA">
<link rel="apple-touch-icon" href="/assets/icons/icon-192x192.png">
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<div id="app">
<header><h1>My PWA</h1></header>
<main id="content">Loading...</main>
<!-- Optional: install button, hidden by default -->
<button id="install-btn" hidden>Install App</button>
</div>
<script src="/app.js"></script>
</body>
</html>
Step 3: Service Worker Registration & Install Prompt (app.js)
// ─── Service Worker Registration ───────────────────────────────────────────
if ('serviceWorker' in navigator) {
window.addEventListener('load', async () => {
try {
const registration = await navigator.serviceWorker.register('/sw.js');
console.log('[App] SW registered, scope:', registration.scope);
} catch (err) {
console.error('[App] SW registration failed:', err);
}
});
}
// ─── Install Prompt (Add to Home Screen) ───────────────────────────────────
let deferredPrompt;
const installBtn = document.getElementById('install-btn'); // may be null if omitted
// Capture the browser's install prompt — it fires before the browser's own UI
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault(); // Stop automatic mini-infobar on mobile
deferredPrompt = e;
if (installBtn) installBtn.hidden = false; // Show your custom install button
});
if (installBt
1---2name: progressive-web-app3description: 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 screen4category: Document Processing5source: antigravity6tags: [javascript, api, claude, ai, document, image, rag, cro]7url: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/progressive-web-app8metadata:9 source: https://skillmd.com/skills/sickn33/progressive-web-app10---111213# Progressive Web Apps (PWAs)1415## Overview1617A 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:18191. **HTTPS** — Required in production for service workers to register (localhost is exempt for development).202. **Web App Manifest** (`manifest.json`) — Makes the app installable and defines its appearance on device home screens.213. **Service Worker** (`sw.js`) — A background script that intercepts network requests, manages caches, and enables offline functionality.2223## When to Use This Skill2425- Use when the user wants their web app to work offline or on unreliable networks.26- Use when building a mobile-first web project where users should be able to install the app to their home screen.27- Use when the user asks about caching strategies, service workers, or improving web app performance and resilience.28- Use when the user mentions Workbox, web app manifests, background sync, or push notifications for the web.29- 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.3031## Deliverables Checklist3233Every PWA implementation must include these files at minimum:3435- [ ] `index.html` — Links manifest, registers service worker36- [ ] `manifest.json` — Full app metadata and icon set37- [ ] `sw.js` — Service worker with install, activate, and fetch handlers38- [ ] `app.js` — Main app logic with SW registration and install prompt handling39- [ ] `offline.html` — Fallback page shown when navigation fails offline (required — missing file will cause install to fail)4041---4243## Step 1: Web App Manifest (`manifest.json`)4445Defines how the app appears when installed. Must be linked from `<head>` via `<link rel="manifest">`.4647```json48{49 "name": "My Awesome PWA",50 "short_name": "MyPWA",51 "description": "A fast, offline-capable Progressive Web App.",52 "start_url": "/",53 "scope": "/",54 "display": "standalone",55 "orientation": "portrait-primary",56 "background_color": "#ffffff",57 "theme_color": "#0055ff",58 "icons": [59 {60 "src": "/assets/icons/icon-192x192.png",61 "sizes": "192x192",62 "type": "image/png",63 "purpose": "any maskable"64 },65 {66 "src": "/assets/icons/icon-512x512.png",67 "sizes": "512x512",68 "type": "image/png",69 "purpose": "any maskable"70 }71 ],72 "screenshots": [73 {74 "src": "/assets/screenshots/desktop.png",75 "sizes": "1280x720",76 "type": "image/png",77 "form_factor": "wide"78 }79 ]80}81```8283**Key fields:**84- `display`: `standalone` hides browser UI; `minimal-ui` shows minimal controls; `browser` is standard tab.85- `purpose: "maskable"` on icons enables adaptive icons on Android (safe zone matters — keep content in center 80%).86- `screenshots` is optional but required for Chrome's enhanced install dialog on desktop.8788---8990## Step 2: HTML Shell (`index.html`)9192```html93<!DOCTYPE html>94<html lang="en">95<head>96 <meta charset="UTF-8">97 <meta name="viewport" content="width=device-width, initial-scale=1.0">98 <title>My Awesome PWA</title>99100 <!-- PWA manifest -->101 <link rel="manifest" href="/manifest.json">102103 <!-- Theme color for browser chrome -->104 <meta name="theme-color" content="#0055ff">105106 <!-- iOS-specific (Safari doesn't fully use manifest) -->107 <meta name="apple-mobile-web-app-capable" content="yes">108 <meta name="apple-mobile-web-app-status-bar-style" content="default">109 <meta name="apple-mobile-web-app-title" content="MyPWA">110 <link rel="apple-touch-icon" href="/assets/icons/icon-192x192.png">111112 <link rel="stylesheet" href="/styles.css">113</head>114<body>115 <div id="app">116 <header><h1>My PWA</h1></header>117 <main id="content">Loading...</main>118 <!-- Optional: install button, hidden by default -->119 <button id="install-btn" hidden>Install App</button>120 </div>121 <script src="/app.js"></script>122</body>123</html>124```125126---127128## Step 3: Service Worker Registration & Install Prompt (`app.js`)129130```javascript131// ─── Service Worker Registration ───────────────────────────────────────────132if ('serviceWorker' in navigator) {133 window.addEventListener('load', async () => {134 try {135 const registration = await navigator.serviceWorker.register('/sw.js');136 console.log('[App] SW registered, scope:', registration.scope);137 } catch (err) {138 console.error('[App] SW registration failed:', err);139 }140 });141}142143// ─── Install Prompt (Add to Home Screen) ───────────────────────────────────144let deferredPrompt;145const installBtn = document.getElementById('install-btn'); // may be null if omitted146147// Capture the browser's install prompt — it fires before the browser's own UI148window.addEventListener('beforeinstallprompt', (e) => {149 e.preventDefault(); // Stop automatic mini-infobar on mobile150 deferredPrompt = e;151 if (installBtn) installBtn.hidden = false; // Show your custom install button152});153154if (installBt