I've been looking at gatsbyjs, I think what they're doing probably isn't viable for us...
they are caching a layout, and then rendering content into it client-side
and also caching the content source, I think?
I will look into using the build date as the cache version, but at the moment, I'm not sure how to pass that information to the service worker
also, I think we will run into a problem because the cache for a page will only be updated after the user visits the page.
so, in this flow: visit foo.html (v1) -> cache foo.html (v1) -> foo.html gets updated to v2 -> visit foo.html, the version that will be shown is v1
then, the cache notices that it is stale and gets updated, and the next time the user visits the page it will be v2
the idea that I had was - always go to the network if it's available, and rely on the server to send a 304 if the content hasn't changed. But, also cache files in the service worker. This way, the site will work offline, but always show the most recent version that the user can access.
this is a pretty good summary of different caching strategies: https://jeffy.info/2017/01/24/offline-first-for-your-templated-site-part-2.html
gatsbyjs is using the second option
also, I am a dork:
I used option 1 (which is full cache). It’s simpler to implement and overhead doesn’t matter much for blogs and simpler sites. But I guess I open also to the “application shell”. We can probably eventually support customization (or different task) to support more variants. So I guess it makes sense to start with the one that is more interesting to you personally. I don’t have opinion on it so far
I think I like option 1 as well, with the caveat that it probably shouldn't be used for larger sites. But also I think the network should be used if it is available, in preference to the cache, because of the stale content problem.
Yeah, agree. Btw, do you know what is the size of the cache? I saw different strategies for caching. I saw caching only links you opened, or cache entire site in background on first open (that is what I did for my personal site)