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
* Minor improvements around importScripts.
- In the "perform the fetch" steps for importScripts(), return the
response, not its unsafe response. These steps run inside "fetch a
classic worker-imported script"[1], which extract the unsafe response,
so getting the unsafe response twice is redundant or wrong.
- Extract a "bad import script response" definition for resuability.
- Rename variables to avoid shadowing.
- Skip fetching the main resource again, when doing the import scripts
update check.
- Make the "perform the fetch" steps in Update asynchronously
complete with a response rather than returning true, as is expected
of these steps.[2]
[1] https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-worker-imported-script
[2] https://html.spec.whatwg.org/multipage/webappapis.html#fetching-scripts-perform-fetch
* The [=current global object=]'s [=force bypass cache for importscripts flag=] is set.
2073
2073
* |registration|'s [=last update check time=] is not null and the time difference in seconds calculated by the current time minus |registration|’s [=last update check time=] is greater than 86400.
2074
2074
1. Let |response| be the result of [=fetch|fetching=] |request|.
2075
-
1. Set |response| to |response|'s [=unsafe response=].
2076
2075
1. If |response|’s [=response/cache state=] is not "`local`", set |registration|’s [=service worker registration/last update check time=] to the current time.
2077
-
1. [=Extract a MIME type=] from the |response|'s [=response/header list=]. If this MIME type (ignoring parameters) is not a [=JavaScript MIME type=], return a [=network error=].
2078
-
1. If |response|'s [=response/type=] is not "`error`", and |response|'s [=response/status=] is an <a>ok status</a>, then:
2079
-
1. [=map/Set=] |serviceWorker|'s [=script resource map=][|request|'s [=request/url=]] to |response|.
2080
-
1. Set |serviceWorker|'s [=classic scripts imported flag=].
2076
+
1. If |response|'s [=unsafe response=] is a [=bad import script response=], then return a [=network error=].
2077
+
1. [=map/Set=] |serviceWorker|'s [=script resource map=][|request|'s [=request/url=]] to |response|.
2078
+
1. Set |serviceWorker|'s [=classic scripts imported flag=].
A <dfn id="dfn-scope-to-job-queue-map">scope to job queue map</dfn> is an <a>ordered map</a> where the keys are [=service worker registration/scope urls=], [=URL serializer|serialized=], and the values are [=job queues=].
2206
2204
2205
+
A <dfn id="dfn-bad-import-script-response">bad import script response</dfn> is a [=/response=] for which any of the following conditions are met:
2206
+
2207
+
* |response|'s [=response/type=] is "`error`"
2208
+
* |response|'s [=response/status=] is not an [=ok status=]
2209
+
* The result of [=Extract a MIME type|extracting a MIME type=] from |response|'s [=response/header list=] is not a [=JavaScript MIME type=]
2210
+
2211
+
Note: Keep this definition in sync with [=fetch a classic worker-imported script=].
1. If |response|'s [=response/cache state=] is not "`local`", set |registration|'s [=last update check time=] to the current time.
2457
2463
1. If |newestWorker| is null, or |newestWorker|'s [=script resource map=][|request|'s [=request/url=]]'s [=response/body=] is not byte-for-byte identical with |response|'s [=response/body=], set |hasUpdatedResources| to true.
2458
2464
1. Else if |newestWorker|'s [=classic scripts imported flag=] is set, then:
1. Let |request| be a new [=/request=] whose [=request/url=] is |url|, [=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.
2461
-
1. Set |request|'s [=request/cache mode=] to "`no-cache`" if any of the following are true:
2465
+
2466
+
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.
2470
+
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.
2471
+
1. Set |importRequest|'s [=request/cache mode=] to "`no-cache`" if any of the following are true:
2462
2472
* |registration|'s [=service worker registration/update via cache mode=] is "`none`".
2463
2473
* |job|'s [=force bypass cache flag=] is set.
2464
2474
* |registration|'s [=last update check time=] is not null and the time difference in seconds calculated by the current time minus |registration|’s [=last update check time=] is greater than 86400.
2465
-
1. Let |fetchedResponse| be the result of [=fetch|fetching=] |request|.
2475
+
1. Let |fetchedResponse| be the result of [=fetch|fetching=] |importRequest|.
2476
+
1. Set |updatedResourceMap|[|importRequest|'s [=request/url=]] to |fetchedResponse|.
2466
2477
1. Set |fetchedResponse| to |fetchedResponse|'s [=unsafe response=].
2467
-
1. Set |updatedResourceMap|[|request|'s [=request/url=]] to |fetchedResponse|.
2468
2478
1. If |fetchedResponse|'s [=response/cache state=] is not "`local`", set |registration|’s [=last update check time=] to the current time.
2469
-
1. [=Extract a MIME type=] from the |fetchedResponse|'s [=response/header list=]. If this MIME type (ignoring parameters) is not a [=JavaScript MIME type=], asynchronously complete these steps with a [=network error=].
2470
-
1. If |fetchedResponse|'s [=response/type=] is "`error`", or |fetchedResponse|'s [=response/status=] is not an [=ok status=], asynchronously complete these steps with a [=network error=].
2471
-
1. If |fetchedResponse|'s [=response/body=] is not byte-for-byte identical with |storedResponse|'s [=response/body=], set |hasUpdatedResources| to true.
2479
+
1. If |fetchedResponse| is a [=bad import script response=], then asynchronously complete these steps with a [=network error=].
2480
+
1. If |fetchedResponse|'s [=response/body=] is not byte-for-byte identical with |storedResponse|'s [=unsafe response=]'s [=response/body=], set |hasUpdatedResources| to true.
2472
2481
2473
2482
Note: The control does not break the loop in this step to continue with all the imported scripts to populate the cache.
2474
-
1. Return true.
2483
+
1. Asynchronously complete these steps with |response|.
2475
2484
2476
2485
If the algorithm asynchronously completes with null, then:
0 commit comments