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
This change includes/considers the following:
- Include imported scripts to byte-check (for classic scripts).
- Compare responses' body instead of source text as per whatwg/html#3316.
- Handle duplicate importScripts() as per #1041.
- Replace *imported scripts updated flag* referenced in importScripts()
by using service worker's state item.
- Have Update's perform the fetch steps cover module scripts.
- Avoid dobule-download of imported scripts pointed out in #1023 (comment).
This change basically makes it check out if the main script resource is
identical to the existing resource. If so, it returns; otherwise, it
creates a new service worker and evalute it to check out if any imported
scripts are changed. It continues with Install only when any of the
resources has been changed. With the change, importScripts() returns
resources from the cache for any duplicated requests including the
request for the main script.
Fixes#1041, #1212, #1023.
A [=/service worker=] has an associated <dfn export id="dfn-skip-waiting-flag">skip waiting flag</dfn>. Unless stated otherwise it is unset.
167
167
168
-
A [=/service worker=] has an associated <dfn export id="dfn-imported-scripts-updated-flag">imported scripts updated flag</dfn>. It is initially unset.
168
+
A [=/service worker=] has an associated <dfn export id="dfn-classic-scripts-imported-flag">classic scripts imported flag</dfn>. It is initially unset.
169
+
170
+
A [=/service worker=] has an associated <dfn export id="dfn-include-updated-resources-flag">include updated resources flag</dfn>. It is initially unset.
169
171
170
172
A [=/service worker=] has an associated <dfn export id="dfn-set-of-event-types-to-handle">set of event types to handle</dfn> (a [=ordered set|set=]) whose [=list/item=] is an <a>event listener</a>'s event type. It is initially an empty set.
When the <dfn method for="ServiceWorkerGlobalScope" id="importscripts-method"><code>importScripts(|urls|)</code></dfn> method is called on a {{ServiceWorkerGlobalScope}} object, the user agent *must* <a>import scripts into worker global scope</a>, given this {{ServiceWorkerGlobalScope}} object and |urls|, and with the following steps to [=fetching scripts/perform the fetch=] given the [=/request=] |request|:
2028
2030
2029
2031
1. Let |serviceWorker| be |request|'s [=request/client=]'s [=environment settings object/global object=]'s [=ServiceWorkerGlobalScope/service worker=].
2030
-
1. If |serviceWorker|'s <a>imported scripts updated flag</a> is unset, then:
2031
-
1. Let |registration| be |serviceWorker|'s [=containing service worker registration=].
2032
-
1. Set |request|'s [=service-workers mode=] to "`none`".
2033
-
1. Set |request|'s [=request/cache mode=] to "<code>no-cache</code>" if any of the following are true:
2034
-
* |registration|'s [=service worker registration/update via cache mode=] is "`none`".
2035
-
* The [=current global object=]'s [=force bypass cache for importscripts flag=] is set.
2036
-
* |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.
2037
-
1. Let |response| be the result of <a lt="fetch">fetching</a> |request|.
2038
-
1. If |response|’s <a for="response" href="https://github.com/whatwg/fetch/issues/376">cache state</a> is not "<code>local</code>", set |registration|’s [=service worker registration/last update check time=] to the current time.
2039
-
1. [=Extract a MIME type=] from the |response|'s [=unsafe response=]'s [=response/header list=]. If this MIME type (ignoring parameters) is not a [=JavaScript MIME type=], return a [=network error=].
2040
-
1. If |response|'s <a>unsafe response</a>'s [=response/type=] is not "<code>error</code>", and |response|'s [=response/status=] is an <a>ok status</a>, then:
2041
-
1. [=map/Set=]<a>script resource map</a>[|request|'s [=request/url=]] to |response|.
2042
-
1. Return |response|.
2043
-
1. Else:
2044
-
1. If <a>script resource map</a>[|url|][=map/exists=], return <a>script resource map</a>[|url|].
1. If |serviceWorker|'s [=state=] is *installed*, *activating*, *activated*, or *redundant*, return a [=network error=].
2034
+
1. Let |registration| be |serviceWorker|'s [=containing service worker registration=].
2035
+
1. Set |request|'s [=service-workers mode=] to "`none`".
2036
+
1. Set |request|'s [=request/cache mode=] to "<code>no-cache</code>" if any of the following are true:
2037
+
* |registration|'s [=service worker registration/update via cache mode=] is "`none`".
2038
+
* The [=current global object=]'s [=force bypass cache for importscripts flag=] is set.
2039
+
* |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.
2040
+
1. Let |response| be the result of <a lt="fetch">fetching</a> |request|.
2041
+
1. If |response|’s <a for="response" href="https://github.com/whatwg/fetch/issues/376">cache state</a> is not "<code>local</code>", set |registration|’s [=service worker registration/last update check time=] to the current time.
2042
+
1. [=Extract a MIME type=] from the |response|'s [=unsafe response=]'s [=response/header list=]. If this MIME type (ignoring parameters) is not a [=JavaScript MIME type=], return a [=network error=].
2043
+
1. If |response|'s <a>unsafe response</a>'s [=response/type=] is not "<code>error</code>", and |response|'s [=response/status=] is an <a>ok status</a>, then:
2044
+
1. Let |newestWorker| be the result of running [=Get Newest Worker=] with |registration|.
2045
+
1. Let |resource| be null.
2046
+
1. If |newestWorker| is not null, set |resource| to |newestWorker|'s [=service worker/script resource map=][|request|'s [=request/url=]], or null if it does not [=map/exist=].
2047
+
1. Set |serviceWorker|'s [=service worker/include updated resources flag=] if any of the following are true:
2048
+
* |newestWorker| is null.
2049
+
* |resource| is null.
2050
+
* |resource|'s [=response/body=] is not byte-for-byte identical with |response|'s [=response/body=].
2051
+
1. [=map/Set=][=service worker/script resource map=][|request|'s [=request/url=]] to |response|.
2052
+
1. Set |serviceWorker|'s [=classic scripts imported flag=].
[=/Service workers=] introduce new persistent storage features including <a>scope to registration map</a> (for [=/service worker registrations=] and their [=/service workers=]), [=request response list=] and <a>name to cache map</a> (for caches), and <a>script resource map</a> (for script resources). In order to protect users from any potential <a biblio data-biblio-type="informative" lt="unsanctioned-tracking">unsanctioned tracking</a> threat, these persistent storages *should* be cleared when users intend to clear them and *should* maintain and interoperate with existing user controls e.g. purging all existing persistent storages.
2080
+
[=/Service workers=] introduce new persistent storage features including <a>scope to registration map</a> (for [=/service worker registrations=] and their [=/service workers=]), [=request response list=] and <a>name to cache map</a> (for caches), and [=service worker/script resource map=] (for script resources). In order to protect users from any potential <a biblio data-biblio-type="informative" lt="unsanctioned-tracking">unsanctioned tracking</a> threat, these persistent storages *should* be cleared when users intend to clear them and *should* maintain and interoperate with existing user controls e.g. purging all existing persistent storages.
A <a>job</a> has a <dfn id="dfn-job-worker-type">worker type</dfn> ("<code>classic</code>" or "<code>module</code>").
2149
2157
2158
+
A [=job=] has a <dfn export id="dfn-job-script-resource-map">script resource map</dfn> which is an <a>ordered map</a> where the keys are [=/URLs=] and the values are [=/responses=].
2159
+
2150
2160
A <a>job</a> has an <dfn id="dfn-job-update-via-cache-mode">update via cache mode</dfn>, which is "`imports`", "`all`", or "`none`".
2151
2161
2162
+
A [=job=] has a <dfn id="dfn-job-potentially-include-updated-resources-flag">potentially include updated resources flag</dfn>. It is initially unset.
2163
+
2152
2164
A <a>job</a> has a <dfn id="dfn-job-client">client</dfn> (a [=/service worker client=]). It is initially null.
2153
2165
2154
2166
A <a>job</a> has a <dfn>referrer</dfn> (a [=/URL=] or null).
1. Invoke [=Reject Job Promise=] with |job| and "{{SecurityError}}" {{DOMException}}.
2420
2432
1. Asynchronously complete these steps with a <a>network error</a>.
2433
+
1. Set |job|'s [=job/potentially include updated resources flag=] if any of the following are true:
2434
+
* |newestWorker| is null.
2435
+
* |newestWorker|'s [=classic scripts imported flag=] is set.
2436
+
* |newestWorker|'s [=service worker/script resource map=][|request|'s [=request/url=]]'s [=response/body=] is not byte-for-byte identical with |response|'s [=response/body=].
2437
+
1. Set |job|'s [=job/script resource map=][|request|'s [=request/url=]] to |response|.
2421
2438
1. If |response|'s <a for="response" href="https://github.com/whatwg/fetch/issues/376">cache state</a> is not "<code>local</code>", set |registration|'s <a>last update check time</a> to the current time.
2422
2439
2423
2440
Issue: The response's cache state concept had been removed from fetch. The fetch issue <a href="https://github.com/whatwg/fetch/issues/376">#376</a> tracks the request to restore the concept or add some similar way to check this state.
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
2435
2452
2436
2453
Else, continue the rest of these steps after the algorithm's asynchronous completion, with |script| being the asynchronous completion value.
2437
-
2438
-
1. If |newestWorker| is not null, |newestWorker|'s [=service worker/script url=] [=url/equals=] |job|'s [=job/script url=], and |script|'s [=source text=] is a byte-for-byte match with |newestWorker|'s [=script resource=]'s [=source text=], if |script| is a [=classic script=], and |script|'s [=module script/module record=]'s \[[ECMAScriptCode]] is a byte-for-byte match with |newestWorker|'s [=script resource=]'s [=module script/module record=]'s \[[ECMAScriptCode]] otherwise, then:
2454
+
1. If |job|'s [=job/potentially include updated resources flag=] is unset, then:
2439
2455
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
2456
+
1. Invoke [=Finish Job=] with |job| and abort these steps.
2457
+
1. Let |worker| be a new [=/service worker=].
2458
+
1. Set |worker|'s [=service worker/script url=] to |job|'s [=job/script url=], |worker|'s <a>script resource</a> to |script|, and |worker|'s [=service worker/type=] to |job|'s <a>worker type</a>.
1. Set |worker|'s [=service worker/script resource map=][|url|] to |response|.
2461
+
1. Set |worker|'s <a>script resource</a>'s <a>HTTPS state</a> to |httpsState|.
2462
+
1. Set |worker|'s <a>script resource</a>'s [=script resource/referrer policy=] to |referrerPolicy|.
2463
+
1. Invoke <a>Run Service Worker</a> algorithm given |worker|, and with the *force bypass cache for importscripts flag* set if |job|'s [=job/force bypass cache flag=] is set.
2464
+
1. If an uncaught runtime script error occurs during the above step, then:
2465
+
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
2466
+
1. If |newestWorker| is null, invoke <a>Clear Registration</a> algorithm passing |registration| as its argument.
2440
2467
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
2441
-
1. Else:
2442
-
1. Let |worker| be a new [=/service worker=].
2443
-
1. Set |worker|'s [=service worker/script url=] to |job|'s [=job/script url=], |worker|'s <a>script resource</a> to |script|, and |worker|'s [=service worker/type=] to |job|'s <a>worker type</a>.
2444
-
1. Set |worker|'s <a>script resource</a>'s <a>HTTPS state</a> to |httpsState|.
2445
-
1. Set |worker|'s <a>script resource</a>'s [=script resource/referrer policy=] to |referrerPolicy|.
2446
-
1. Invoke <a>Run Service Worker</a> algorithm given |worker|, and with the *force bypass cache for importscripts flag* set if |job|'s [=job/force bypass cache flag=] is set.
2447
-
1. If an uncaught runtime script error occurs during the above step, then:
2448
-
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
2449
-
1. If |newestWorker| is null, invoke <a>Clear Registration</a> algorithm passing |registration| as its argument.
2450
-
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
2468
+
1. If |worker|'s [=classic scripts imported flag=] is set, and |worker|'s [=service worker/include updated resources flag=] is unset, then:
2469
+
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
2470
+
1. Invoke [=Finish Job=] with |job| and abort these steps.
2451
2471
1. Invoke <a>Install</a> algorithm with |job|, |worker|, and |registration| as its arguments.
0 commit comments