Build a service worker app from scratch, in stages.
https://portsoc.github.io/hsww/
index.html
contains a single heading.style.css
is a short css file that changes the colour of the heading.script.js
is a simple client JS script that writes to the console on page load.
img/192.png
a 192x192 pixel png logo.index.html
links to logo as shortcut icon and anapple-touch-icon
(used for bookmarks).
script.js
add code to register a Service Workersw.js
is the new Service Worker script that runs in the background and writes to the console on registration.
script.js
attempts to fetch a text message to modify the "Hello World" text.sw.js
adds 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.
sw.js
uses theinstall
event to add a cache and populate it with a list of cacheable files.
sw.js
uses the cache (and only the cache) to respond to fetch requests, so there's no network traffic at all.
sw.js
interceptFetch is refactored to call the handleFetch method, ready for stage 8.
sw.js
when 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.
manifest.json
is added specifying the data necessary for a device to be able to bookmark and run the app.index.html
is modified to refer tomanifest.json
sw.js
is modified to addmanifest.json
to the list of cacheable files.
manifest.json
is added specifying the data necessary for a device to be able to bookmark and run the app.index.html
is modified to refer tomanifest.json
sw.js
is modified to addmanifest.json
to the list of cacheable files.