Definisi
Dari Berbagai Sumber
- Google web fundamentals: Script that your browser runs in the background, separate from a web page, opening the door to features that don’t need a web page or user interaction
- Google PWA: JavaScript file that runs separately from the main browser thread, intercepting network requests, caching or retrieving resources from the cache, and delivering push messages
- Mozilla dev: Event-driven worker registered against an origin and a path. It takes the form of a JavaScript file that can control the web-page/site that it is associated with, intercepting and modifying navigation and resource requests, and caching resources in a very granular fashion to give you complete control over how your app behaves in certain situations (the most obvious one being when the network is not available).
- File Javascript
- Jalan di background dengan thread terpisah
- Ngatur hal-hal yang ga butuh interaksi UI
- proxy network
- caching
- menangkap push message
- mengirim notification
Catatan Penting !
- Service worker tidak akan terpasang jika ada error bahkan secuil pun, Chrome mempermudah tracking error Service worker
- Kemungkinan penyebab eror:
- Salah tempat / state eksekusi function
- Direktori untuk di cache tidak bisa terbuka, misal menggunakan Google Cloud Storage (tidak ada dir listing)
- Pahami Service worker lifecycle, fungsi2 bisa dijalankan ketika statenya sudah active, kalau baru registrasi saja, belum bisa
- Registration
- Installation
- Activation
Penggunaan
- Untuk menangkap Push API dari server ke client
- Untuk mengirim Notif API dari client ke client
Artikel Terkait
Artikel Tidak Terkait
service-worker
pwa
notifications