- From: Rhys Evans <notifications@github.com>
- Date: Wed, 17 Aug 2016 09:55:25 -0700
- To: slightlyoff/ServiceWorker <ServiceWorker@noreply.github.com>
- Message-ID: <slightlyoff/ServiceWorker/issues/959@github.com>
There's a couple of race conditions arising in the SW I'm working on relating to prefetch/preload: 1. Once a user has navigated to a page I send off a request to prefetch the next page, this comes back with a load of link headers for css & js resources, which I also prefetch. There is a chance that the user will navigate to this next page before all those requests have responded. How can I force the new request (and all its related preload requests for the links) to use the requests that are already in flight? 2. I have a css file containing my critical path css. On the first page load this is inlined, but a link=preload header also tells the browser to fetch it as a standalone file so that when the sw kicks in it can safely request the page without inlined css. But in the SW I don't know if the browser supports preload so, to be on the safe side, I may want to manually request all the files in the link headers. For browsers that _do_ support preload this will mean unnecessary doubling of requests. It'd be useful to have a pending requests API, with similar request matching rules to the cache API. Could it even be built into the Cache API? e.g. ```js cache.open('mycache') .then(() => { cache.set(request, fetch(request).then(res => { // optionally either throw to reject, or return res to put in cache }) } ``` If the promise rejects, or resolves with anything other than a response then the response would not be put in the cache. `cache.get(request)` would resolve/reject when the promise resolves/rejects -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/slightlyoff/ServiceWorker/issues/959
Received on Wednesday, 17 August 2016 16:55:53 UTC