Progressive Web Apps (PWA)
Build installable, offline-capable web apps using Service Workers, Web App Manifests, and caching strategies.
0 of 5 concepts completed (0%)
What You'll Learn
Tutorial Contents
1.Web App Manifest
// manifest.json (linked from <head>)
{
"name": "My Progressive App",
"short_name": "MyApp",
"description": "A fast, installable web application",
"start_url": "/",
"display": "standalone",
"orientation": "portrait",
"theme_color": "#6200ee",
"background_color": "#ffffff",
"icons": [
{ "src": "/icons/icon-72.png", "sizes": "72x72", "type": "image/png" },
{ "src": "/icons/icon-192.png", "sizes": "192x192","type": "image/png" },
{ "src": "/icons/icon-512.png", "sizes": "512x512","type": "image/png",
"purpose": "any maskable" }
],
"screenshots": [
{ "src": "/screenshots/desktop.png", "sizes": "1280x720", "form_factor": "wide" },
{ "src": "/screenshots/mobile.png", "sizes": "390x844" }
],
"categories": ["productivity", "utilities"],
"shortcuts": [
{
"name": "New Task",
"url": "/new",
"icons": [{ "src": "/icons/add-96.png", "sizes": "96x96" }]
}
]
}<head>
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#6200ee" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="apple-touch-icon" href="/icons/icon-192.png" />
</head>2.Service Worker & Caching Strategies
// service-worker.js
const STATIC_CACHE = "static-v2";
const DYNAMIC_CACHE = "dynamic-v2";// Install precache static assets self.addEventListener("install", (event) => { event.waitUntil( caches.open(STATIC_CACHE).then((cache) => cache.addAll(STATIC_ASSETS)) ); self.skipWaiting(); // activate immediately });
// Activate clean old caches self.addEventListener("activate", (event) => { event.waitUntil( caches.keys().then((keys) => Promise.all( keys .filter((k) => k !== STATIC_CACHE && k !== DYNAMIC_CACHE) .map((k) => caches.delete(k)) ) ) ); self.clients.claim(); });
// Fetch stale-while-revalidate for HTML, cache-first for assets self.addEventListener("fetch", (event) => { const { request } = event;
// API calls: network only if (request.url.includes("/api/")) { event.respondWith( fetch(request).catch(() => new Response(JSON.stringify({ error: "Offline" }), { headers: { "Content-Type": "application/json" } }) ) ); return; }
// Static assets: cache first event.respondWith( caches.match(request).then((cached) => { const fetchPromise = fetch(request).then((response) => { caches.open(DYNAMIC_CACHE).then((c) => c.put(request, response.clone())); return response; }); return cached || fetchPromise.catch(() => caches.match("/offline.html") ); }) ); }); ```
Code Example
// service-worker.js
const CACHE = "app-v1";
const ASSETS = ["/", "/index.html", "/styles.css", "/app.js"];
self.addEventListener("install", e => {
e.waitUntil(
caches.open(CACHE).then(cache => cache.addAll(ASSETS))
);
});
self.addEventListener("fetch", e => {
e.respondWith(
caches.match(e.request).then(cached => {
return cached || fetch(e.request).then(response => {
const clone = response.clone();
caches.open(CACHE).then(c => c.put(e.request, clone));
return response;
});
})
);
});Pro Tips
- 1Your service worker must be served from the root scope (/) to intercept all page requests. A worker at /app/sw.js only covers /app/*.
- 2Always version your cache name (cache-v2, cache-v3) and delete old caches in the activate event to prevent stale assets.
- 3Use workbox-webpack-plugin or workbox-build instead of hand-writing service worker logic it handles precaching, routing, and cache strategies reliably.
- 4The Web App Manifest must include at least a 192px and 512px icon for Chrome to show the install prompt.
Topics Covered
Continue Learning
Explore the official documentation and deepen your knowledge with real-world practice.
Explore the Full Portfolio
This is the complete portfolio of Sufi Khan Sulaiman, a technology leader specialising in B2B commerce and digital automation. Start from the Home page for the overview, then move through two decades of career experience across FLIR Systems, Lorex Technology, and 1c Platform, and the full catalogue of project case studies spanning headless commerce migrations, AI recommendation engines, and multi-channel fulfilment systems.
The skills and certifications page maps the technical and leadership capabilities behind the work, while the articles and the knowledge base break down the thinking into actionable frameworks. For hands-on learning, the tutorials and applications sections cover practical builds from front-end fundamentals to full-stack web apps.
For consulting engagement, the expertise page outlines service offerings, the ecommerce hub covers platform architecture and automation strategy, and the ecommerce guide (PDF) is a downloadable 55-page field manual. When you are ready to talk, the contact page is the direct line.