New example: not-so-simple-service-worker #256
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It could use a better name. Please offer suggestions. I have it up and running here:
https://sidewayss.github.io/dom-examples/service-worker/nsssw/
This topic is setup for multiple examples, but as of now there is only one, so I assume that a second example would be desirable. This new example does a few things that the simple-service-worker example does not:
addEventListener("statechange", ...)
postMessage()
cache
variable socaches.open()
doesn't get called so often.then()
instead ofawait
The pretext is a design that, upon
DOMContentLoaded
, wants to pre-cache a set of resources by sub-page. In the example it's a set of images as part of a slideshow. Upon loading the page, the service worker caches all the slideshow images so that they display immediately when the user requests them.The code could use more comments, and I'll add them (or feel free) once the code is generally approved as OK. Same goes for an entry in the readme.md for this repo. #255 is an open PR to add the simple-service-worker example to the readme, and it would be best to merge that, then add this not-so-simple example.
Are there formatting rules for these examples? Should I be running this code through Prettier? If so, just generic Prettier or do you have a specific configuration?
On a related note: I am curious as to the real benefits of implementing the caching scheme illustrated by the simple example. Seems to me that the "install" event
.addAll()
code only provides faster page loading the 2nd time the user visits the page, at which point the service worker is active and all these files will get cached anyway as part of the "fetch" event handler. Am I correct, are there more generalized benefits to that caching scheme?