Service Workers
Why
Modern web apps act a lot more like desktop software than traditional websites, allowing interaction and TODO rather than just showing content. One of the main issues with web apps is the need for an internet connection. Without one, resources including the scripts to run the app can't be fetched.
Service workers solve this problem by allowing the app to configure how it should cache resources locally to use without fetching. A service worker can be used by any web app to continue running when the internet disconnects, or even to run offline.
What
TODO define worker TODO limited execution time or something?
A service worker is an event driven worker script which acts as a proxy for network requests. It receives fetch events from the webpage and can respond to them however it wants based on the conditions, for example pulling the age from a cache if there is no network connection. Service workers can also run tasks at periodic intervals to synchronise with a server, for example to check for updates to the webapp. As well as receiving push notifications, among other things.
Service workers are installed in the web browser by the webapp and run in a background thread, as a result, they can't block the app from running, but have no access to the page.
TODO screenshots of service workers
Lifecycle
synchronous not allowed, no local storage Can use indexedDB
register/install fetch events periodic sync
self
file hashes and cache busting
Registering
HTTPS, or localhost alarm instead of timer?
In Firefox, Service Worker APIs are hidden and cannot be used when the user is in private browsing mode, or when history is disabled, or if cookies are cleared when Firefox is closed.
navigation preload
Updating
Scope
the scope option can't give a scope broarder than the path