Re: [ServiceWorker] Support restarting download when storing large resources in Cache (#713)

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](https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#dfn-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.

`cache.put(request, response)` should probably fail if the response is 206. I'm not against the cache returning 206 (or 416) responses if `cache.match(request)` is called and the `request` has a range header.

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:

```js
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?).

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/713#issuecomment-114896111

Received on Wednesday, 24 June 2015 14:51:22 UTC