-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Required and optional payloads for precaching #155
Comments
There is nothing to stop a developer implementing this themselves - just alter the caching array based on some criteria. let cacheArray = [
{url: '/index.html', revision: '1234'}
];
if (someExternalSaveDataValue) {
cacheArray = cacheArray.concat([
'/styles/optional-css.1234.css'
]);
}
precacheManager.cacheRevisionedAssets(cacheArray); I suppose the loss here is that on a manifest change and optional parameter would be deleted if it was previously cached and in a data saver install it won't make the cache list (You'd want the cache revision to be checked and the optional cache entry deleted if the revision is now out of date). When you say two glob patterns, I'm not sure what you mean, a glob pattern that gets compared to the URL's? Feels a bit error prone (i.e. I know I'd mess up the regex for the value some where). I'd probably go down a more declarative approach:
We could also do the same for the unrevisioned assets (i.e. only cache specific assets and ignore the others. |
Sorry, I was conflating And then what you describe Beyond that, I don't think there's that much to change, apart from that extra logic when the manifest is updated:
|
I'm going to close this in favor of seeing if anyone requests this. At the moment developers have the following options:
|
Just wanted to say that I've been thinking about this for my "prefetchcache top 10 articles" idea, which is a use case largely for news publishers. It would dovetail into this nicely, where those 10 articles would be marked as "optional", and then I wouldn't need to develop heuristics around Save-Data, CT, and ECT. |
I'm going to re-open this issue for consideration in a future release, and move over @merlinnot's comment from #1283 (comment) to consolidate:
|
I'm still confused as to what the request is here. All of the above sounds like its logic specific to an app and it's separate to precaching (i.e. precache a small set and cache other stuff seperately at another time). So what is Workbox doing / not-doing that is required here? |
Hmm, maybe I've made a little typo in point 4: resources should be cached, not _pre_cached. Basically that would be nice to enable precaching programatically so it doesn't use network resources until I want it to. Currently there's no way to use it in the way I've presented which would be the most efficient. |
My hunch is that you might be able to do this with the lower level PrecacheController this does a lot of the same behavior as the default |
I think my default webpack precache has become too large (install is starting to trigger burst throttling on nginx) So I thought to split up precaching into two smaller groups of files
I thought it would be cool to use the same underlying cache for both groups
Fine, I have to create a custom PrecacheController If I tweak workbox-precaching slightly
It seems to be possible
The first group of files is cached immediately Is this barking up the wroing tree though? |
I posted a related use case on stack overflow, and @jeffposnick suggested I move the discussion here, so I'll paste below: There are cases where an application might need a relatively large resource as a strict requirement, but only in certain cases that are not easily detectable from a service worker. For example:
One approach would be to manually exclude certain files from the precache manifest and then to conditionally load those files from the scripts on the main thread to be stored in the runtime cache. But then those files are not precached - they're only loaded after the new version activates, by which point you may no longer be online. Is there a solution that allows the following?:
|
We've got a use case related to However, we also have a lot of static files that are not part of the single-page app. E.g. data policy and terms & conditions as static .html, robots.txt, images, etc etc. And with We could use I imagine that if optional precaching was implemented, I could just let all those static files be optional. We use In the meanwhile, is the only solution to try to maintain a |
Hello @johanarnor—I'm not sure that optional payloads for precaching are the best approach to solving what you're trying to do. If you want to use precaching and Please note that you say that some examples of URLs that you need exempted from |
Many thanks @jeffposnick for your detailed reply. Much appreciated! You're right that optional payloads probably wouldn't solve my issue. It was kind of build around an assumption that all webpack assets that weren't precached could be optionally precached instead. So I switched to You're also right about users not generally navigating to files like |
Hi there, Workbox is moving to a new engineering team within Google. As part of this move, we're declaring a partial bug bankruptcy to allow the new team to start fresh. We realize this isn't optimal, but realistically, this is the only way we see it working. For transparency, here're the criteria we applied:
Thanks, and we hope for your understanding! |
Something that we've thought about in the past (see GoogleChromeLabs/sw-precache#145) is support for optional precaching payloads that can be toggling on or off based on some criteria like the presence of the
Save-Data: on
header (though that's not exposed on theinstall
handler at the moment).It might be a good idea to brainstorm about what the interface could look like in the context of
sw-precaching
, apart from the question of how to signal to the service worker which payloads to download.A straightforward approach would be to take in two different
glob
patterns, one for the required and then the other for an optional payload. By default only the required ones get cached in theinstall
handler.If we follow the pattern suggested at #136 (comment), where the
PrecacheManager
is responsible for creating aRoute
with aCacheFirst
strategy for requests it knows about, I don't think we'd have to do much extra to handle requests that fall into the "optional" bucket. TheCacheFirst
behavior will fall back to the network for optional URLs that aren't already cached, using the response to populate the cache for next time.We would have to add in some extra logic to handle manifest updates, to check whether an optional URL is already cached, and ignore manifest hash updates for optional URLs when it is not already cached.
CC: @alxhub @gauntface @addyosmani
The text was updated successfully, but these errors were encountered: