What is Service Worker
Script for background browser work
Service Worker — a script that the browser runs in the background separately from the web page, providing features that don't require a web page or user interaction.
Key capabilities
- Offline mode — app works without internet
- Push notifications — receive notifications even with browser closed
- Background sync — data synchronization in background
- Caching — resource cache management
- Request interception — proxy for network requests
Lifecycle
- Registration — Service Worker registration
- Installation — installation and resource caching
- Activation — activation and old cache cleanup
- Fetch — network request interception
- Update — updating to new version
Caching strategies
- Cache First — cache first, then network
- Network First — network first, then cache
- Stale While Revalidate — cache + background update
- Cache Only — cache only
- Network Only — network only
Applications
- PWA — progressive web applications
- Offline-first — offline priority applications
- Performance — faster page loading
- Push API — web push notifications
- Background Sync — deferred data synchronization