A background task to perform:
- Caching
- Background sync
- Listens to push notifications
Process
- First visit - service worker is installed (Client → Server)
- Online mode - service worker acting as a proxy (Client → Service Worker → Server)
- Offline mode - service worker responding with cached responses (Client → Service Worker → Cache)
Registering A Worker
<script>
if ('serviceWorker' in navigator){
navigator.serviceWorker.register('/sw.js');
}
</script>