What is Service Worker?
A JavaScript file that runs in the background, enabling offline support, push notifications, and background sync for web apps.
Service workers act as programmable network proxies between the browser and server. They intercept network requests, cache resources, and serve cached content when offline. This enables Progressive Web App (PWA) capabilities.
The lifecycle includes registration, installation (cache assets), and activation (clean old caches). The fetch event handler implements caching strategies: cache-first, network-first, stale-while-revalidate. Service workers also enable push notifications and background sync.