[ServiceWorker] Prefetching resources using SW (#570)

This issue is for adding support to SW to prefetch resources during onfetch that it knows a controlled page will later request.

Imagine a page at www.example.com/foo/bar that has ```<image src="bar.png">``` or does an XHR to ```www.example.net/bar```. Currently the page must be fetched and parsed before the image or XHR fetch begins. It could be helpful if SW could prefetch the resources in the ```onfetch``` handler for "/foo/bar", and return the response (possibly an in-progress stream) in the ```onfetch``` handler for "bar.png" or /bar".

One idea is to use the cache for this:
```javascript
// in onfetch for /foo/bar
cache.add('bar.png');
// in onfetch for bar.png
event.respondWith(cache.match('bar.png'));
```

But as currently spec'd, the ```.match``` call wouldn't succeed until the request initiated by the ```.add``` call completes.

Is there another way of supporting this use case?

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

Received on Monday, 1 December 2014 07:09:13 UTC