From 365b215888fbef42fb5fd6dbddcbdd961f4d340d Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Fri, 13 Oct 2017 13:08:28 +0100 Subject: [PATCH 1/3] Remove foreign fetch --- docs/index.bs | 285 +------------------------------------------------- 1 file changed, 4 insertions(+), 281 deletions(-) diff --git a/docs/index.bs b/docs/index.bs index 732c1be9..d5daef74 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -12,7 +12,7 @@ Editor: Marijn Kruisselbrink, Google, mek@chromium.org Repository: w3c/ServiceWorker Group: serviceworkers !Tests: web-platform-tests service-workers/ (ongoing work) -Status Text: This is a living document addressing new features including foreign fetch, header-based installation, navigation preload, etc. Readers need to be aware that this specification may include unstable features. Service Workers 1 is a version that is advancing toward a W3C Recommendation. +Status Text: This is a living document. Readers need to be aware that this specification may include unimplemented features, and details that may change. Service Workers 1 is a version that is advancing toward a W3C Recommendation. Abstract: This specification describes a method that enables applications to take advantage of persistent background processing, including hooks to enable bootstrapping of web applications while offline. Abstract: Abstract: The core of this system is an event-driven Web Worker, which responds to events dispatched from documents and other sources. A system for managing installation, versions, and upgrades is provided. @@ -170,10 +170,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe A [=/service worker=] has an associated set of extended events (a [=ordered set|set=]) whose [=list/item=] is an {{ExtendableEvent}}. It is initially an empty set. - A [=/service worker=] has an associated list of foreign fetch scopes whose element type is a [=/URL=]. It is initially empty. - - A [=/service worker=] has an associated list of foreign fetch origins whose element type is a [=/URL=]. It is initially empty. -

Lifetime

@@ -887,7 +883,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe attribute EventHandler oninstall; attribute EventHandler onactivate; attribute EventHandler onfetch; - attribute EventHandler onforeignfetch; // event attribute EventHandler onmessage; // event.source of the message events is Client object @@ -951,10 +946,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe onfetch {{fetch!!event}} - - onforeignfetch - {{foreignfetch!!event}} - onmessage {{message!!event}} @@ -1359,49 +1350,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe * Adding a promise to the event's extend lifetime promises delays treating the active worker as *activated* until all the promises in the extend lifetime promises settle. (See step 12.3 of Activate algorithm.) This is primarily used to ensure that any functional events are not dispatched to the {{ServiceWorkerGlobalScope}} object that represents the [=/service worker=] until it upgrades database schemas and deletes the outdated cache entries.
-
-

{{InstallEvent}}

- -
-      [Constructor(DOMString type, optional ExtendableEventInit eventInitDict), Exposed=ServiceWorker]
-      interface InstallEvent : ExtendableEvent {
-        void registerForeignFetch(ForeignFetchOptions options);
-      };
-
-      dictionary ForeignFetchOptions {
-        required sequence<USVString> scopes;
-        required sequence<USVString> origins;
-      };
-    
- -
-

{{InstallEvent/registerForeignFetch(options)|event.registerForeignFetch(options)}}

- - {{InstallEvent/registerForeignFetch(options)}} registers this service worker to handle foreign fetches from certain origins for certain sub scopes. - - registerForeignFetch(|options|) method *must* run these steps: - - 1. If the dispatch flag is unset, [=throw=] an "{{InvalidStateError}}" {{DOMException}}. - 1. If |options|.{{ForeignFetchOptions/origins}} is empty, [=throw=] a TypeError. - 1. Let |originURLs| be an empty list of [=/URLs=]. - 1. If the value of |options|.{{ForeignFetchOptions/origins}} is not a single string equal to a single U+002A ASTERISK character (*): - 1. For each |origin| in |options|.origins: - 1. If the value of |origin| is not an absolute-URL string, [=throw=] a TypeError. - 1. Add the result of parsing |origin| to |originURLs|. - 1. If |options|.{{ForeignFetchOptions/scopes}} is empty, [=throw=] a TypeError. - 1. Let |scopeString| be the context object's relevant global object's [=ServiceWorkerGlobalScope/service worker=]'s containing service worker registration's [=service worker registration/scope url=], serialized. - 1. Let |subScopeURLs| be an empty list of [=/URLs=]. - 1. For each |subScope| in |options|.{{ForeignFetchOptions/scopes}}: - 1. Let |subScopeURL| be the result of parsing |subScope| with context object's relevant settings object's API base URL. - 1. If |subScopeURL| is failure, [=throw=] a TypeError. - 1. Let |subScopeString| be the serialized |subScopeURL|. - 1. If |subScopeString| does not start with |scopeString|, [=throw=] a TypeError. - 1. Add |subScopeURL| to |subScopeURLs|. - 1. Set this [=/service worker=]'s list of foreign fetch scopes to |subScopeURLs|. - 1. Set this [=/service worker=]'s list of foreign fetch origins to |originURLs|. -
-
-

{{FetchEvent}}

@@ -1536,122 +1484,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
-
-

{{ForeignFetchEvent}}

- -
-      [Constructor(DOMString type, ForeignFetchEventInit eventInitDict), Exposed=ServiceWorker]
-      interface ForeignFetchEvent : ExtendableEvent {
-        [SameObject] readonly attribute Request request;
-        readonly attribute USVString origin;
-
-        void respondWith(Promise<ForeignFetchResponse> r);
-      };
-
-      dictionary ForeignFetchEventInit : ExtendableEventInit {
-        required Request request;
-        USVString origin = "null";
-      };
-
-      dictionary ForeignFetchResponse {
-        required Response response;
-        USVString origin;
-        sequence<ByteString> headers;
-      };
-    
- - [=/Service workers=] have a functional event {{foreignfetch!!event}}. For {{foreignfetch!!event}} events, [=/service workers=] use the {{ForeignFetchEvent}} interface which extends the {{ExtendableEvent}} interface. - - Each event using {{ForeignFetchEvent}} interface has an associated potential response (a [=/response=]), initially set to null, an associated origin (a {{USVString}} or null), initially set to null, an associated list of exposed headers (whose element type is a byte string), initially set to an empty list, and the following associated flags that are initially unset: - - * wait to respond flag - * respond-with entered flag - * respond-with error flag - -
-

{{ForeignFetchEvent/request|event.request}}

- - The request attribute *must* return the value it was initialized to. -
- -
-

{{ForeignFetchEvent/origin|event.origin}}

- - The origin attribute *must* return the value it was initialized to. -
- -
-

{{ForeignFetchEvent/respondWith(r)|event.respondWith(r)}}

- - Note: Developers can set the argument |r| with either a promise that resolves with a {{Response}} object or a {{Response}} object (which is automatically cast to a promise). Otherwise, a network error is returned to [=/Fetch=]. Renderer-side security checks about tainting for cross-origin content are tied to the types of filtered responses defined in [=/Fetch=]. - - respondWith(|r|) method *must* run these steps: - -
- 1. If the dispatch flag is unset, [=throw=] an "{{InvalidStateError}}" {{DOMException}}. - 1. If the [=ForeignFetchEvent/respond-with entered flag=] is set, [=throw=] an "{{InvalidStateError}}" {{DOMException}}. - 1. Add |r| to the extend lifetime promises. - 1. Increment the [=ExtendableEvent/pending promises count=] by one. - - Note: The [=ExtendableEvent/pending promises count=] is incremented even if the given promise has already been settled. The corresponding count decrement is done in the microtask queued by the reaction to the promise. - - 1. Upon [=upon fulfillment|fulfillment=] or [=upon rejection|rejection=] of |r|, [=queue a microtask=] to run these substeps: - 1. Decrement the [=ExtendableEvent/pending promises count=] by one. - 1. Let |registration| be the [=context object=]'s [=relevant global object=]'s associated [=ServiceWorkerGlobalScope/service worker=]'s [=containing service worker registration=]. - 1. If |registration|'s [=uninstalling flag=] is set, invoke [=Try Clear Registration=] with |registration|. - 1. If |registration| is not null, invoke [=Try Activate=] with |registration|. - - Note: {{ForeignFetchEvent/respondWith(r)|event.respondWith(r)}} extends the lifetime of the event by default as if {{ExtendableEvent/waitUntil()|event.waitUntil(r)}} is called. - - 1. Set the stop propagation flag and stop immediate propagation flag. - 1. Set the [=ForeignFetchEvent/respond-with entered flag=]. - 1. Set the [=ForeignFetchEvent/wait to respond flag=]. - 1. Let |targetRealm| be the relevant Realm of the context object. - 1. Run the following substeps in parallel: - 1. Wait until |r| settles. - 1. If |r| rejected, then: - 1. Set the [=ForeignFetchEvent/respond-with error flag=]. - 1. If |r| resolved with |response|, then: - 1. If |response| is a {{ForeignFetchResponse}}, then: - 1. Set the [=ForeignFetchEvent/origin=] to |response|.{{ForeignFetchResponse/origin}}. - 1. Set the list of exposed headers to |response|.{{ForeignFetchResponse/headers}}. - 1. If |response|.{{ForeignFetchResponse/response}} is [=Body/disturbed=] or [=Body/locked=], then: - 1. Set the [=ForeignFetchEvent/respond-with error flag=]. - 1. Else: - 1. Let |bytes| be an empty byte sequence. - 1. Let |end-of-body| be false. - 1. Let |done| be false. - 1. Let |potentialResponse| be a copy of |response|.{{ForeignFetchResponse/response}}'s associated [=/response=], except for its [=response/body=]. - 1. If |response|.{{ForeignFetchResponse/response}}'s body is non-null, run these substeps: - 1. Let |reader| be the result of getting a reader from |response|.{{ForeignFetchResponse/response}}'s [=response/body=]'s stream. - 1. Let |strategy| be an object created in |targetRealm|. The user agent may choose any object. - 1. Let |pull| be an action that runs these subsubsteps: - 1. Let |promise| be the result of reading a chunk from |response|.{{ForeignFetchResponse/response}}'s [=response/body=]'s stream with |reader|. - 1. When |promise| is fulfilled with an object whose done property is false and whose value property is a Uint8Array object, append the bytes represented by the value property to |bytes| and perform ! DetachArrayBuffer with the ArrayBuffer object wrapped by the value property. - 1. When |promise| is fulfilled with an object whose done property is true, set |end-of-body| to true. - 1. When |promise| is fulfilled with a value that matches with neither of the above patterns, or |promise| is rejected, [=ReadableStream/error=] |newStream| with a TypeError. - 1. Let |cancel| be an action that [=ReadableStream/cancels=] |response|.{{ForeignFetchResponse/response}}'s [=response/body=]'s stream with |reader|. - 1. Let |newStream| be the result of [=ReadableStream/construct a ReadableStream object=] with |strategy|, |pull| and |cancel| in |targetRealm|. - 1. Set |potentialResponse|'s [=response/body=] to a new [=/body=] whose stream is |newStream|. - 1. Run these subsubsteps repeatedly in parallel while |done| is false: - 1. If |newStream| is errored, then set |done| to true. - 1. Otherwise, if |bytes| is empty and |end-of-body| is true, then [=ReadableStream/close=] |newStream| and set |done| to true. - 1. Otherwise, if |bytes| is not empty, run these subsubsubsteps: - 1. Let |chunk| be a subsequence of |bytes| starting from the beginning of |bytes|. - 1. Remove |chunk| from |bytes|. - 1. Let |buffer| be an ArrayBuffer object created in |targetRealm| and containing |chunk|. - 1. [=ReadableStream/Enqueue=] a Uint8Array object created in |targetRealm| and wrapping |buffer| to |newStream|. - 1. Set the [=ForeignFetchEvent/potential response=] to |potentialResponse|. - 1. Else: - 1. Set the [=ForeignFetchEvent/respond-with error flag=]. - - Note: If the [=ForeignFetchEvent/respond-with error flag=] is set, a network error is returned to [=/Fetch=] through [=Handle Foreign Fetch=] algorithm. (See the step 19.1.) Otherwise, a filtered version of |response| is returned to [=/Fetch=] through [=Handle Foreign Fetch=] algorithm. (See the step 20.1.) - - 1. Unset the [=ForeignFetchEvent/wait to respond flag=]. -
-
-
-

{{ExtendableMessageEvent}}

@@ -1722,11 +1554,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe - - install - {{InstallEvent}} - [Lifecycle event] The [=ServiceWorkerGlobalScope/service worker=]'s containing service worker registration's installing worker changes. (See step 11.2 of the Install algorithm.) - activate {{ExtendableEvent}} @@ -1737,11 +1564,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe {{FetchEvent}} [Functional event] The [=/http fetch=] invokes Handle Fetch with |request|. As a result of performing Handle Fetch, the [=ServiceWorkerGlobalScope/service worker=] returns a [=/response=] to the [=/http fetch=]. The [=/response=], represented by a {{Response}} object, can be retrieved from a {{Cache}} object or directly from network using {{WindowOrWorkerGlobalScope/fetch(input, init)|self.fetch(input, init)}} method. (A custom {{Response}} object can be another option.) - - foreignfetch - {{FetchEvent}} - [Functional event] The [=/http fetch=] invokes [=Handle Foreign Fetch=] with |request|. As a result of performing [=Handle Foreign Fetch=], the [=ServiceWorkerGlobalScope/service worker=] returns a [=/response=] to the [=/http fetch=]. The [=/response=], represented by a {{Response}} object, can be retrieved from a {{Cache}} object or directly from network using {{WindowOrWorkerGlobalScope/fetch(input, init)|self.fetch(input, init)}} method. (A custom {{Response}} object can be another option.) - message {{ExtendableMessageEvent}} @@ -1999,7 +1821,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. If |r|'s [=request/url=]'s [=url/scheme=] is not one of "http" and "https", then: 1. [=fetch/Terminate=] all the ongoing [=fetches=] initiated by |requests| with the aborted flag set. 1. Return [=a promise rejected with=] a `TypeError`. - 1. If |r|'s [=request/client=]'s [=environment settings object/global object=] is a {{ServiceWorkerGlobalScope}} object, set |request|'s [=service-workers mode=] to "`foreign`". + 1. If |r|'s [=request/client=]'s [=environment settings object/global object=] is a {{ServiceWorkerGlobalScope}} object, set |request|'s [=service-workers mode=] to "`none`". 1. Set |r|'s [=request/initiator=] to "`fetch`" and [=request/destination=] to "`subresource`". 1. Add |r| to |requestList|. 1. Let |responsePromise| be [=a new promise=]. @@ -2296,7 +2118,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. Let |serviceWorker| be |request|'s [=request/client=]'s [=environment settings object/global object=]'s [=ServiceWorkerGlobalScope/service worker=]. 1. If |serviceWorker|'s imported scripts updated flag is unset, then: 1. Let |registration| be |serviceWorker|'s [=containing service worker registration=]. - 1. Set |request|'s [=service-workers mode=] to "`foreign`". + 1. Set |request|'s [=service-workers mode=] to "`none`". 1. Set |request|'s [=request/cache mode=] to "no-cache" if any of the following are true: * |registration|'s [=service worker registration/update via cache mode=] is "`none`". * The [=current global object=]'s [=force bypass cache for importscripts flag=] is set. @@ -2752,7 +2574,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. Let |installingWorker| be |registration|'s installing worker. 1. Invoke Run Service Worker algorithm given |installingWorker|, and with the *force bypass cache for importscripts flag* set if |job|'s [=job/force bypass cache flag=] is set. 1. Queue a task |task| to run the following substeps: - 1. Let |e| be the result of creating an event with {{InstallEvent}}. + 1. Let |e| be the result of creating an event with {{ExtendableEvent}}. 1. Initialize |e|’s {{Event/type}} attribute to {{install!!event}}. 1. Dispatch |e| at |installingWorker|'s [=service worker/global object=]. 1. *WaitForAsynchronousExtensions*: Run the following substeps in parallel: @@ -3026,85 +2848,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. If |request| is a non-subresource request, or |request| is a subresource request and the time difference in seconds calculated by the current time minus |registration|'s last update check time is greater than 86400, invoke Soft Update algorithm with |registration|.
-
-

Handle Foreign Fetch

- - The [=Handle Foreign Fetch=] algorithm is the entry point for the [=/fetch=] handling handed to the [=/service worker=] context to handle foreign fetch requests. - - : Input - :: |request|, a [=/request=] - : Output - :: |response|, a [=/response=] - -
- 1. Let |handleFetchFailed| be false. - 1. Let |respondWithEntered| be false. - 1. Let |eventCanceled| be false. - 1. If |request| is not a subresource request, return null and abort these steps. - - Note: Foreign fetch only allows intercepting of subresource requests. Navigation requests can be intercepted by the regular fetch event anyway, so there is no benefit to supporting those requests here as well. - - 1. If |request|'s [=request/client=] is not a secure context, return null and abort these steps. - 1. Let |activeWorker| be the result of running the [=Match Service Worker for Foreign Fetch=] algorithm passing |request|'s [=request/url=] as the argument. - 1. If |activeWorker| is null, return null. - 1. If |activeWorker|'s state is *activating*, then: - 1. Wait for |activeWorker|'s state to become *activated*. - 1. If |activeWorker|'s [=environment settings object/origin=] is the same as |request|'s [=request/origin=], return null. - 1. Let |originMatches| be false. - 1. If |activeWorker|'s list of foreign fetch origins is empty, set |originMatches| to true. - 1. For each |origin| in |activeWorker|'s list of foreign fetch origins: - 1. If |origin| is equal to |request|'s [=request/origin=], set |originMatches| to true. - 1. If |originMatches| is false, return null. - 1. If |request|'s [=request/method=] is not a [=CORS-safelisted method=], or if there is at least one [=header=] in |request|'s [=request/header list=] for whose [=header/name=] is not a [=CORS-safelisted request-header=], return null. - - Note: In the future this might be relaxed by adding supported methods and headers to the {{ForeignFetchOptions}}. - - 1. Invoke [=Run Service Worker=] algorithm with |activeWorker| as the argument. - 1. Queue a task |task| to run the following substeps: - 1. Let |e| be the result of creating an event with {{ForeignFetchEvent}}. - 1. Initialize |e|’s {{Event/type}} attribute to {{foreignfetch!!event}}. - 1. Initialize |e|’s {{Event/cancelable}} attribute to true. - 1. Initialize |e|’s {{ForeignFetchEvent/request}} attribute to a new {{Request}} object associated with |request| and a new associated {{Headers}} object whose [=guard=] is "`immutable`". - 1. Initialize |e|’s {{ForeignFetchEvent/origin}} attribute to the Unicode serialization of |request|'s [=request/origin=]. - 1. Dispatch |e| at |activeWorker|'s [=service worker/global object=]. - 1. Invoke [=Update Service Worker Extended Events Set=] with |activeWorker| and |e|. - 1. If |e|'s [=ForeignFetchEvent/respond-with entered flag=] is set, set |respondWithEntered| to true. - 1. If |e|'s wait to respond flag is set, wait until |e|'s wait to respond flag is unset. - 1. Let |internalResponse| be |e|'s [=ForeignFetchEvent/potential response=]. - 1. If |internalResponse| is a filtered response, set |internalResponse| to |internalResponse|'s internal response. - 1. If |e|'s respond-with error flag is set, set |handleFetchFailed| to true. - 1. Else if |e|'s [=ForeignFetchEvent/origin=] is null: - 1. If |e|'s list of exposed headers is not empty, set |handleFetchFailed| to true. - 1. Else if |e|'s [=ForeignFetchEvent/potential response=] is a opaque-redirect filtered response, set |response| to |e|'s [=ForeignFetchEvent/potential response=]. - 1. Else set |response| to an opaque filtered response of |internalResponse|. - 1. Else if |e|'s [=ForeignFetchEvent/origin=] is not equal to the Unicode serialization of |request|'s [=request/origin=], set |handleFetchFailed| to true. - 1. Else if |e|'s [=ForeignFetchEvent/potential response=] is an opaque filtered response or is an opaque-redirect filtered response, set |response| to |e|'s [=ForeignFetchEvent/potential response=]. - 1. Else if |request|'s response tainting is "opaque", set |response| to an opaque filtered response of |internalResponse|. - 1. Else: - 1. Let |headers| be |e|'s list of exposed headers. - 1. If |response| is a CORS filtered response, remove from |internalResponse|'s CORS-exposed header-name list all values not in |headers|. - 1. Else set |internalResponse|'s CORS-exposed header-name list to |headers|. - 1. Set |response| to a CORS filtered response of |internalResponse|. - 1. If |e|'s canceled flag is set, set |eventCanceled| to true. - - If |task| is discarded or the script has been aborted by the termination of |activeWorker|, set |handleFetchFailed| to true. - - The |task| *must* use |activeWorker|'s event loop and the handle fetch task source. - - 1. Wait for |task| to have executed or been discarded. - 1. If |respondWithEntered| is false, then: - 1. If |eventCanceled| is true, then: - 1. Return a network error. - 1. Else: - 1. Return null. - 1. If |handleFetchFailed| is true, then: - 1. Return a network error. - 1. Else: - 1. Return |response|. - -
-
-

Handle Functional Event

@@ -3375,26 +3118,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 1. Return |registration|.
-
-

Match Service Worker for Foreign Fetch

- - : Input - :: |requestURL|, a [=/URL=] - : Output - :: |worker|, a [=/service worker=] - - 1. Run the following steps atomically. - 1. Let |registration| be the result of running the [=Match Service Worker Registration=] algorithm passing |requestURL| as the argument. - 1. If |registration| is null, return null. - 1. Let |worker| be |registration|'s [=service worker registration/active worker=]. - 1. If |worker| is null, return null. - 1. Let |requestURLString| be the serialized |requestURL|. - 1. For each [=/URL=] |scope| in |worker|'s list of foreign fetch scopes: - 1. Let |scopeString| be the serialized |scope|. - 1. If |requestURLString| starts with |scopeString| return |worker|. - 1. Return null. -
-

Get Registration

From 30e665b2c80a4c7c9b60874c41b07b7467c35e99 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Wed, 25 Oct 2017 15:07:26 +0100 Subject: [PATCH 2/3] Shouldn't have removed install event --- docs/index.bs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/index.bs b/docs/index.bs index d5daef74..8b273dd6 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -1554,6 +1554,11 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe + + install + {{ExtendableEvent}} + [Lifecycle event] The [=ServiceWorkerGlobalScope/service worker=]'s containing service worker registration's installing worker changes. (See step 11.2 of the Install algorithm.) + activate {{ExtendableEvent}} From 781bef8e94e7821d506a3b9c78536ab725afd7b3 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Thu, 16 Nov 2017 15:04:04 +0000 Subject: [PATCH 3/3] Removing link header --- docs/index.bs | 94 --------------------------------------------------- 1 file changed, 94 deletions(-) diff --git a/docs/index.bs b/docs/index.bs index 8b273dd6..f9b6d03d 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -1584,100 +1584,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
-
- - - A [=/service worker registration=] and its [=service worker registration/scope url=] are created by a serviceworker link, which is declared using a "serviceworker" `Link` header or a <{link}> element whose <{link/rel}> attribute contains the keyword "<{link/rel/serviceworker}>". - -
- - - A serviceworker link can be declared using a `Link` header [[!RFC8288]] with "`serviceworker`" as the value of the "`rel`" parameter and a [=URL serializer|serialized=] [=service worker/script url=] inside angle brackets ("`<>`") as the [=link target=], and the following optional [=target attributes=]: - - : `scope` - :: Value: A [=URL serializer|serialized=] [=service worker registration/scope url=]. - - : `workertype` - :: Value: A [=job/worker type=]. - - : `updateviacache` - :: Value: An [=service worker registration/update via cache mode=]. - - The "`anchor`" parameter must not be specified. - -
-
-        Link: <sw.js>; rel="serviceworker"; scope="/"; workertype="module"; updateviacache="all"
-      
-
- -
- -
- - - When a user agent that supports [[!RFC8288]] processes a Link header that contains a serviceworker link, the user agent *should* run these steps: - - 1. If the Link header has an "anchor" parameter, abort these steps. - 1. Let |contextURL| be the result of parsing the [=link context=] of the Link header. - 1. If the result of running potentially trustworthy origin with the [=environment settings object/origin=] of |contextURL| is Not Trusted, abort these steps. - 1. Let |request| be the [=/request=] for which this header was received in the response. - 1. If |request|'s [=request/client=] is not a secure context, abort these steps. - 1. Let |scriptURL| be the result of parsing the [=link target=] of the Link header. - 1. Let |scopeURL| be null. - 1. If the "scope" [=target attribute=] of the Link header is present, set |scopeURL| to the result of parsing the "scope" [=target attribute=] with |scriptURL|. - 1. Let |workerType| be the "workertype" [=target attribute=] of the Link header, or "classic" if no such attribute is present. - 1. If |workerType| is not a valid {{WorkerType}} value, abort these steps. - 1. Let |updateViaCache| be the "`updateviacache`" [=target attribute=] of the `Link` header, or "`imports`" if no such attribute is present. - 1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, a new promise, null, |contextURL|, |workerType|, and |updateViaCache|. -
- -
- - - When a serviceworker link's <{link}> element is inserted into a document, or a serviceworker link is created on a <{link}> element that is already in a document tree, or the <{link/href}>, <{link/scope}>, or <{link/updateviacache}> attributes of the <{link}> element of a serviceworker link is changed, the user agent *should* run these steps: - - 1. If the <{link/href}> attribute is the empty string, abort these steps. - 1. Let |client| be the document's [=ServiceWorkerContainer/service worker client=]. - 1. If |client| is not a secure context, queue a task to fire an event named error at the <{link}> element, and abort these steps. - 1. Let |scriptURL| be the result of parsing the <{link/href}> attribute with the <{link}> element's node document's document base URL. - 1. Let |scopeURL| be null. - 1. If the <{link/scope}> attribute is present, set |scopeURL| to the result of parsing the <{link/scope}> attribute with the <{link}> element's node document's document base URL. - 1. Let |workerType| be the state of the <{link/workertype}> attribute. - 1. If |workerType| is invalid, abort these steps. - 1. Let |updateViaCache| be the <{link/updateviacache}> attribute, or "`imports`" if the <{link/updateviacache}> attribute is omitted. - 1. Let |promise| be a new promise. - 1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, |promise|, |client|, |client|'s creation URL, |workerType|, and |updateViaCache|. - 1. Run the following substeps in parallel: - 1. Wait until |promise| settles. - 1. If |promise| rejected, queue a task to fire an event named error at the <{link}> element. - 1. If |promise| resolved, queue a task to fire an event named load at the <{link}> element. - - The serviceworker link element *must not* [=document/delay the load event=] of the element's node document. - -
- A resource being loaded with the following response header: - -
-        Link: </js/sw.js>; rel="serviceworker"; scope="/"
-      
- - has more or less the same effect as a document being loaded in a secure context with the following - link element: - -
-        <link rel="serviceworker" href="/js/sw.js" scope="/">
-      
- - which is more or less equivalent to the page containing JavaScript code like: - -
-        navigator.serviceWorker.register("/js/sw.js", { scope: "/" });
-      
-
-
-
-

Caches