You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve "update via cache" and "worker type" in register algorithms. (#1411)
This makes the following changes:
* updateViaCache is a live property. This is mostly covered by the WPT
registration-updateviacache.https.html. A test that the updateViaCache
change is only committed if the register() call resolves is added in
web-platform-tests/wpt#17131.
* Changing worker type bypasses the byte-for-byte update check. This is covered
by WPT update-registration-with-type.https.html.
* Adds Worker type and updateViaCache to the job equivalence check. A
test for this is added in web-platform-tests/wpt#17131.
Addresses #1189, #1408, #1359, and #1358.
Note: The {{ServiceWorkerContainer/register(scriptURL, options)}} method creates or updates a [=/service worker registration=] for the given [=service worker registration/scope url=]. If successful, a [=/service worker registration=] ties the provided |scriptURL| to a [=service worker registration/scope url=], which is subsequently used for <a lt="handle fetch">navigation matching</a>.
639
639
640
-
<dfn method for="ServiceWorkerContainer"><code>register(|scriptURL|, |options|)</code></dfn> method *must* run these steps:
640
+
The <dfn method for="ServiceWorkerContainer"><code>register(|scriptURL|, |options|)</code></dfn> method *must* run these steps:
641
641
642
642
1. Let |p| be a <a>promise</a>.
643
643
1. Let |client| be the <a>context object</a>'s [=ServiceWorkerContainer/service worker client=].
Two <a>jobs</a> are <dfn id="dfn-job-equivalent">equivalent</dfn> when their <a>job type</a> is the same and:
2251
2251
2252
-
* For *register* and *update* <a>jobs</a>, both their [=job/scope url=] and the [=job/script url=] are the same.
2252
+
* For *register* and *update* <a>jobs</a>, their [=job/scope url=], [=job/script url=], [=job/worker type=], and [=job/update via cache mode=] are the same.
2253
2253
* For *unregister* <a>jobs</a>, their [=job/scope url=] is the same.
2254
2254
2255
2255
A <dfn id="dfn-job-queue">job queue</dfn> is a thread safe [=queue=] used to synchronize the set of concurrent [=jobs=]. The [=job queue=] contains [=jobs=] as its [=queue/items=]. A [=job queue=] is initially empty.
1. If |registration|'s <a>uninstalling flag</a> is set, unset it.
2439
2439
1. Let |newestWorker| be the result of running the <a>Get Newest Worker</a> algorithm passing |registration| as the argument.
2440
-
1. If |newestWorker| is not null, |job|'s [=job/script url=] [=url/equals=] |newestWorker|'s [=service worker/script url=], and |job|'s [=job/update via cache mode=]'s value equals |registration|'s [=service worker registration/update via cache mode=], then:
2440
+
1. If |newestWorker| is not null, |job|'s [=job/script url=] [=url/equals=] |newestWorker|'s [=service worker/script url=], |job|'s [=job/worker type=] equals |newestWorker|'s [=service worker/type=], and |job|'s [=job/update via cache mode=]'s value equals |registration|'s [=service worker registration/update via cache mode=], then:
2441
2441
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
2442
2442
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
1. Let |updatedResourceMap| be an [=ordered map=] where the [=map/keys=] are [=/URLs=] and the [=map/values=] are [=/responses=].
2468
-
1. Switching on |job|'s <a>worker type</a>, run these substeps with the following options:
2468
+
1. Switching on |job|'s [=worker type=], run these substeps with the following options:
2469
2469
<!-- TODO: reorganize algorithm so that the worker environment is created before fetching happens -->
2470
2470
: "<code>classic</code>"
2471
2471
:: <a>Fetch a classic worker script</a> given |job|’s <a lt="URL serializer">serialized</a>[=job/script url=], |job|’s [=job/client=], "<code>serviceworker</code>", and the to-be-created <a>environment settings object</a> for this service worker.
1. If |response|'s [=response/cache state=] is not "`local`", set |registration|'s [=last update check time=] to the current time.
2518
-
1. Let |map| be |newestWorker|'s [=script resource map=] if |newestWorker| is not null, and null otherwise.
2519
-
1. If |map| is null or |map|[|url|]'s [=response/body=] is not byte-for-byte identical with |response|'s [=response/body=], set |hasUpdatedResources| to true.
2520
-
1. Else if |newestWorker|'s [=classic scripts imported flag=] is set, then:
2518
+
1. Set |hasUpdatedResources| to true if any of the following are true:
2519
+
* |newestWorker| is null.
2520
+
* |newestWorker|'s [=service worker/script url=] is not |url| or |newestWorker|'s [=service worker/type=] is not |job|'s [=worker type=].
2521
+
* |newestWorker|'s [=script resource map=][|url|]'s [=response/body=] is not byte-for-byte identical with |response|'s [=response/body=].
2522
+
1. If |hasUpdatedResources| is false and |newestWorker|'s [=classic scripts imported flag=] is set, then:
2521
2523
2522
2524
Note: The following checks to see if an imported script has been updated, since the main script has not changed.
1. If |importUrl| is |request|'s [=request/url=], then continue.
2527
+
1. If |importUrl| is |url|, then continue.
2526
2528
1. Let |importRequest| be a new [=/request=] whose [=request/url=] is |importUrl|, [=request/client=] is |job|'s [=job/client=], [=request/destination=] is "`script`", [=request/parser metadata=] is "`not parser-inserted`", [=request/synchronous flag=] is set, and whose [=request/use-URL-credentials flag=] is set.
2527
2529
1. Set |importRequest|'s [=request/cache mode=] to "`no-cache`" if any of the following are true:
2528
2530
* |registration|'s [=service worker registration/update via cache mode=] is "`none`".
0 commit comments