-
Notifications
You must be signed in to change notification settings - Fork 312
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
Support restarting download when storing large resources in Cache #713
Comments
cc @brittanystoroz |
Can the current cache API be made to handle that kind of scenario? I reckon we want a very similar setup to whatever we do for HTTP range internally. See also whatwg/fetch#38 |
Cache would have to grow the concept of partial entries like our internal http cache has. I'm not sure what the API would look like, though. |
Can you explain the data model? Or maybe @jakearchibald can figure this out? |
Hah, I've been staring at this issue for like 20 mins before your comment appeared. Ok, brain dumping: So the cache does have the concept of an incumbent record, which is used to store a backup complete entry while the main entry is incomplete, and may yet fail. That takes care of cache matches while the entry is still being streamed to the cache. The cache should yield the in-progress entry, which is handy for larger responses. But I'm not convinced we should keep the partial entry around if streaming failed.
As for downloading a large resource, I think we need a way of doing that that allows the service worker to terminate & come back with an event when the download is complete. Would that solve this issue? Eg: cache.backgroundDownloadThisPlease(request);
// then later…
self.addEventListener('backgrounddownloadcomplete', event => {
event.cache;
event.request;
event.response;
}); The background downloader is welcome to do ranges and combine them, it may show a downloading notification to the user showing progress (optional?). |
If we want to go low-level, we could have something like |
Is this the same thing as background sync? What about something like Alternatively, we could do nothing and make the SW do the merging in script. Once Streams is more widely available this could be done in a memory efficient way. It would just be a fair amount of boilerplate to write. Match all your partial responses, create a new response with a pipe body, and then concat the partial responses into the new pipe. |
Background sync keeps the SW open to get a fulfill/reject response from the promise passed to
I guess if |
https://github.com/WICG/background-fetch is now a thing 😄 |
Has the concept of caching partial content responses been revisited? Im interested in the following concepts specifically:
We have a use-case that requires all three of these and currently don't see any way to implement this using the current API semantics. There's an example here that shows how to read a partial content response from a complete entry, but this sadly isn't sufficient for us. |
Closing this in favour of https://github.com/WICG/background-fetch. We can look at storing partial responses in another issue, but I feel like making request/response storable in IDB might be a better first step, as it would enable these kind of things to be easier-built. |
Recently I noticed that a website was using SW+Cache to offline its app shell, but it was using FileSystem API to store its videos:
http://richapps.de/taking-the-web-offline-service-worker/
What features might be missing to force the use of FileSystem?
It seems one might be the ability to start downloading a large resource, start it streaming into Cache, network interruption occurs, and then continue the download when network is restored.
I believe Cache currently rejects the cache.put() or cache.add() if the body errors out. (Or rather its currently vaguely spec'd.) There is definitely no way to continue a partially stored download, though.
Thoughts?
@jakearchibald @annevk
The text was updated successfully, but these errors were encountered: