Skip to content

Commit 53e78bf

Browse files
committed
Support ServiceWorkerAutoPreload behavior
1 parent 1d795e2 commit 53e78bf

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

docs/index.bs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32133213
1. Let |shouldSoftUpdate| be true if any of the following are true, and false otherwise:
32143214
* |request| is a [=non-subresource request=].
32153215
* |request| is a [=subresource request=] and |registration| is [=stale=].
3216+
1. Let |raceResponse| be null.
32163217
1. If |activeWorker|'s [=service worker/list of router rules=] [=list/is not empty=]:
32173218
1. Let |source| be the result of running the [=Get Router Source=] algorithm with |registration|'s <a>active worker</a> and |request|.
32183219
1. If |source| is {{RouterSourceEnum/"network"}}:
@@ -3241,7 +3242,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32413242
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
32423243
1. Let |queue| be an empty [=queue=] of [=/response=].
32433244
1. Let |raceFetchController| be null.
3244-
1. Let |raceResponse| be a [=race response=] whose [=race response/value=] is "<code>pending</code>".
3245+
1. Set |raceResponse| to be a [=race response=] whose [=race response/value=] is "<code>pending</code>".
32453246
1. Run the following substeps [=in parallel=], but [=abort when=] |fetchController|'s [=fetch controller/state=] is "<code>terminated</code>" or "<code>aborted</code>":
32463247
1. Set |raceFetchController| to the result of calling [=fetch=] given |request|, with [=fetch/processResponse=] set to the following steps given a [=/response=] |raceNetworkRequestResponse|:
32473248
1. If |raceNetworkRequestResponse|'s [=response/status=] is [=ok status=], then:
@@ -3259,29 +3260,43 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32593260
1. Wait until |queue| is not empty.
32603261
1. Return the result of [=dequeue=] |queue|.
32613262
1. Assert: |source| is "{{RouterSourceEnum/fetch-event}}"
3262-
1. If |request| is a [=navigation request=], |registration|'s [=navigation preload enabled flag=] is set, |request|'s [=request/method=] is \`<code>GET</code>\`, |registration|'s [=active worker=]'s [=set of event types to handle=] [=set/contains=] <code>fetch</code>, and |registration|'s [=active worker=]'s [=all fetch listeners are empty flag=] is not set then:
3263-
3264-
Note: If the above is true except |registration|'s [=active worker=]'s <a>set of event types to handle</a> **does not** contain <code>fetch</code>, then the user agent may wish to show a console warning, as the developer's intent isn't clear.
3265-
3266-
1. Let |preloadRequest| be the result of [=request/cloning=] the request |request|.
3267-
1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=].
3268-
1. Let |preloadResponseObject| be a new {{Response}} object associated with a new {{Headers}} object whose [=guard=] is "`immutable`".
3269-
1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is \`<code>Service-Worker-Navigation-Preload</code>\` and [=header/value=] is |registration|'s [=navigation preload header value=].
3270-
1. Set |preloadRequest|'s [=service-workers mode=] to "`none`".
3271-
1. Let |preloadFetchController| be null.
3272-
1. Run the following substeps [=in parallel=], but [=abort when=] |fetchController|'s [=fetch controller/state=] is "<code>terminated</code>" or "<code>aborted</code>":
3273-
1. Set |preloadFetchController| to the result of [=Fetch|fetching=] |preloadRequest|.
3274-
3275-
To [=fetch/processResponse=] for |navigationPreloadResponse|, run these substeps:
3276-
3277-
1. If |navigationPreloadResponse|'s [=response/type=] is "`error`", reject |preloadResponse| with a `TypeError` and terminate these substeps.
3278-
1. Associate |preloadResponseObject| with |navigationPreloadResponse|.
3279-
1. Resolve |preloadResponse| with |preloadResponseObject|.
3280-
1. [=If aborted=], then:
3281-
1. Let |deserializedError| be the result of [=deserialize a serialized abort reason=] given null and |workerRealm|.
3282-
1. [=fetch controller/Abort=] |preloadFetchController| with |deserializedError|.
3263+
1. If |request| is a [=navigation request=], |request|'s [=request/method=] is \`<code>GET</code>\`, |registration|'s [=active worker=]'s [=set of event types to handle=] [=set/contains=] <code>fetch</code>, and |registration|'s [=active worker=]'s [=all fetch listeners are empty flag=] is not set then:
3264+
1. If |registration|'s [=navigation preload enabled flag=] is set then:
3265+
3266+
Note: If the above is true except |registration|'s [=active worker=]'s <a>set of event types to handle</a> **does not** contain <code>fetch</code>, then the user agent may wish to show a console warning, as the developer's intent isn't clear.
3267+
3268+
1. Let |preloadRequest| be the result of [=request/cloning=] the request |request|.
3269+
1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=].
3270+
1. Let |preloadResponseObject| be a new {{Response}} object associated with a new {{Headers}} object whose [=guard=] is "`immutable`".
3271+
1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is \`<code>Service-Worker-Navigation-Preload</code>\` and [=header/value=] is |registration|'s [=navigation preload header value=].
3272+
1. Set |preloadRequest|'s [=service-workers mode=] to "`none`".
3273+
1. Let |preloadFetchController| be null.
3274+
1. Run the following substeps [=in parallel=], but [=abort when=] |fetchController|'s [=fetch controller/state=] is "<code>terminated</code>" or "<code>aborted</code>":
3275+
1. Set |preloadFetchController| to the result of [=Fetch|fetching=] |preloadRequest|.
3276+
3277+
To [=fetch/processResponse=] for |navigationPreloadResponse|, run these substeps:
3278+
3279+
1. If |navigationPreloadResponse|'s [=response/type=] is "`error`", reject |preloadResponse| with a `TypeError` and terminate these substeps.
3280+
1. Associate |preloadResponseObject| with |navigationPreloadResponse|.
3281+
1. Resolve |preloadResponse| with |preloadResponseObject|.
3282+
1. [=If aborted=], then:
3283+
1. Let |deserializedError| be the result of [=deserialize a serialized abort reason=] given null and |workerRealm|.
3284+
1. [=fetch controller/Abort=] |preloadFetchController| with |deserializedError|.
3285+
1. Else, a user agent may run the following substeps:
3286+
3287+
Note: A user agent may speculatively dispatch a network request in parallel with creating a fetch event in order to minimize the bootstrap cost.
3288+
3289+
1. Let |autoPreloadFetchController| be null.
3290+
1. Set |raceResponse| to be a [=race response=] whose [=race response/value=] is "<code>pending</code>".
3291+
1. Run the following substeps [=in parallel=], but [=abort when=] |fetchController|'s [=fetch controller/state=] is "<code>terminated</code>" or "<code>aborted</code>":
3292+
1. Set |autoPreloadFetchController| to the result of calling [=fetch=] given |request|, with [=fetch/processResponse=] set to the following steps given a [=/response=] |autoPreloadRequestResponse|:
3293+
1. If |autoPreloadRequestResponse|'s [=response/status=] is [=ok status=], set |raceResponse|'s [=race response/value=] to |autoPreloadRequestResponse|.
3294+
1. [=If aborted=] and |autoPreloadFetchController| is not null, then:
3295+
1. [=fetch controller/Abort=] |autoPreloadFetchController|.
3296+
1. Set |raceResponse| to a [=race response=] whose [=race response/value=] is null.
3297+
1. Resolve |preloadResponse| with undefined.
32833298
1. Else, resolve |preloadResponse| with undefined.
3284-
1. Return the result of [=Create Fetch Event and Dispatch=] with |request|, |registration|, |useHighResPerformanceTimers|, |timingInfo|, |workerRealm|, |reservedClient|, |preloadResponse|, and null.
3299+
1. Return the result of [=Create Fetch Event and Dispatch=] with |request|, |registration|, |useHighResPerformanceTimers|, |timingInfo|, |workerRealm|, |reservedClient|, |preloadResponse|, and |raceResponse|.
32853300
</section>
32863301

32873302
<section algorithm>

0 commit comments

Comments
 (0)