Build a service worker app from scratch, in stages.
https://portsoc.github.io/hsww/
index.htmlcontains a single heading.style.cssis a short css file that changes the colour of the heading.script.jsis a simple client JS script that writes to the console on page load.
Stage 2: Add a favicon (see the diff)
img/192.pnga 192x192 pixel png logo.index.htmllinks to logo as shortcut icon and anapple-touch-icon(used for bookmarks).
Stage 3: Register a Service Worker (see the diff)
script.jsadd code to register a Service Workersw.jsis the new Service Worker script that runs in the background and writes to the console on registration.
Stage 4: Logging Fetch Events with a Service Worker (see the diff)
script.jsattempts to fetch a text message to modify the "Hello World" text.sw.jsadds an event listener for fetch events, and logs each one. Notice that the service workers is installed when the page is loaded, so only really starts to be visible on reload.
Stage 5: Adding a Cache (see the diff)
sw.jsuses theinstallevent to add a cache and populate it with a list of cacheable files.
Stage 6: Fetch from Cache (see the diff)
sw.jsuses the cache (and only the cache) to respond to fetch requests, so there's no network traffic at all.
Stage 7: Refactor (see the diff)
sw.jsinterceptFetch is refactored to call the handleFetch method, ready for stage 8.
Stage 8: Updating the Cache (see the diff)
sw.jswhen a resource is requested, it is immediately served from the cache, and a network request is used to update the cache in the background. The SW is not allowed to go idle until the cache is updated.
Stage 9: Make it installable with a Manifest (see the diff)
manifest.jsonis added specifying the data necessary for a device to be able to bookmark and run the app.index.htmlis modified to refer tomanifest.jsonsw.jsis modified to addmanifest.jsonto the list of cacheable files.
Stage 10: Address additional Lighthouse requirements (see the diff)
manifest.jsonis added specifying the data necessary for a device to be able to bookmark and run the app.index.htmlis modified to refer tomanifest.jsonsw.jsis modified to addmanifest.jsonto the list of cacheable files.