Answer
A Service Worker is a proxy script between the page and network, enabling offline support, push notifications, and custom caching. Runs on a separate thread; communicates via postMessage.
Lifecycle: register → install (precache) → activate (cleanup old caches) → fetch events.
Caching strategies:
| Strategy | Use case |
|---|---|
| Cache-first | Static assets (fonts, icons) |
| Network-first | API data, always-fresh HTML |
| Stale-while-revalidate | Avatars, non-critical JSON |
| Network-only | Payments, auth endpoints |