mediumFrontend EngineerTechnology
How do Service Workers enable Progressive Web Apps (PWAs)?
Posted 18/04/2026
by Mehedy Hasan Ador
Question Details
"We want our app to work offline and be installable. How do Service Workers make this possible?"
Suggested Solution
Service Worker: Proxy between app and network
// sw.js — Cache-first strategy
self.addEventListener("fetch", (e) => {
e.respondWith(caches.match(e.request).then(cached => cached || fetch(e.request)));
});
// Install: precache critical assets
self.addEventListener("install", (e) => {
e.waitUntil(caches.open("v1").then(cache => cache.addAll(["/", "/styles.css", "/app.js"])));
});
PWA Requirements
- HTTPS
- Service Worker
- Web App Manifest (
manifest.json)
| Feature | Without SW | With SW |
|---|---|---|
| Offline | ❌ Blank page | ✅ Cached content |
| Install | ❌ Bookmark only | ✅ Home screen icon |
| Push notifications | ❌ | ✅ |
| Background sync | ❌ | ✅ |