service worker

service worker is javascript that can intercept the process to fetch resources.

example

ServiceWorker.js

1. use the url as a key to match the resource from the cache.
2. if the resource does not match, fetch it from online and if the response is ok(200), put it to the cache.

caches.has()
check existence of the cache
caches.open()
get the cache
cache.match()
match the resource from the cache
cache.put()
put the resource to the cache

html/PWAManager.js

navigator.serviceWorker.register()
register the service worker
navigator.serviceWorker.getRegistration()
get the service worker registration
registration.unregister()
unregister the service worker
caches.has()
check existence of the cache
caches.open()
get the cache
caches.delete()
delete the cache
cache.keys()
get all keys used to match the resource from the cache
cache.delete()
delete the resource from the cache
cache.put()
put the resource to the cache