-
Notifications
You must be signed in to change notification settings - Fork 142
Why caching what we decided not to cache in the example js13kpwa? #2957
Comments
Still sharing my experience, here is what I did as an exercise to test my understanding. I created a separate asset file for the service worker:
Then I modified the service worker as follows:
|
I have thought about this for a while and agree that the tutorial should be more explicit as to whether to cache As It may be a task in the future to update the tutorial to include periodic background sync https://developer.mozilla.org/en-US/docs/Web/API/Web_Periodic_Background_Synchronization_API which allows for data to be updated in the background. I can update the tutorial to be more explicit about why |
@Rumyra sounds good to me, and I think your explanation is sound. |
Thanks @chrisdavidmills I've added: You may notice we haven't cached game.js. This is the file that contains the data we use when displaying our games. In reality this data would most likely come from an API endpoint or database and caching the data would mean updating it periodically when there was network connectivity. We won't go into that here, but the Periodic Background Sync API is good further reading on this topic. At the bottom of this section https://wiki.developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Offline_Service_workers#Lifecycle_of_a_Service_Worker |
Looks great, thanks @Rumyra ! |
My point was that in the example provided, the code (see below) will systematically cache game.js at the first request even though it's not in the list to cache. It might be that this is an aspect that the example did not intend to cover and that a real code in practice would not systematically cache game.js. I am not sure the explanation covers this aspect.
|
I'm going to pick this up again @chrisdavidmills as I overlooked the initial cache. I might go through the tutorial myself and even out anything I find |
Request type
Details
I am sharing the experience that I had while studying the page https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Offline_Service_workers. In the code,
games.js
is not in the list of the shell items to cache. I thought, hey I can add an entry server side and see that it will be updated. It did not work ! It took me a few minutes to realize that in the code below when an item is not found in the cache, we cache it. So, we could as well have includedgames.js
in the list. I found this a bit confusing. The example should be more explicit about whether the goal is to cache every thing (includinggame.js
) or not.The text was updated successfully, but these errors were encountered: