Skip to content
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

Prefetching resources using SW #570

Closed
mfalken opened this issue Dec 1, 2014 · 4 comments
Closed

Prefetching resources using SW #570

mfalken opened this issue Dec 1, 2014 · 4 comments

Comments

@mfalken
Copy link
Member

mfalken commented Dec 1, 2014

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:

// 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?

@gavinp
Copy link

gavinp commented Dec 1, 2014

Isn't this a duplicate of issue 361?

@mfalken
Copy link
Member Author

mfalken commented Dec 3, 2014

Yes looks like this is a particular use case that can be part of issue #361

@mfalken
Copy link
Member Author

mfalken commented Jul 7, 2015

This looks the same as issue #573

@jungkees
Copy link
Collaborator

jungkees commented Jul 8, 2015

The .match promise in the example will resolve with an incumbent record, if there has been any, even before .add promise resolves. Or, if there has been no incumbent record, it will return the in-flight fetching record. The fulfillment of .add promise makes the resource be the new incumbent record for the next request.

Closing.

@jungkees jungkees closed this as completed Jul 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants