diff --git a/docs/index.bs b/docs/index.bs index 6d7969dd..d39f0425 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -74,6 +74,8 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/ text: ancestor origins list; for: Location; url: concept-location-ancestor-origins-list urlPrefix: syntax.html text: delay the load event; for: document; url: delay-the-load-event + urlPrefix: semantics.html + text: serviceworker; for: html; url: link-type-serviceworker spec: fetch; urlPrefix: https://fetch.spec.whatwg.org/ type: dfn @@ -85,6 +87,7 @@ spec: rfc5988; urlPrefix: https://tools.ietf.org/html/rfc5988 type: dfn text: context IRI; url: section-5.2 text: target attribute; url: section-5.4 + text: target attributes; url: section-5.4 text: target IRI; url: section-5.1 spec: rfc7230; urlPrefix: https://tools.ietf.org/html/rfc7230 @@ -1744,12 +1747,36 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
- + - The serviceworker keyword may be used with <{link}> elements. This keyword creates an external resource link (serviceworker link) that is used to declare a [=/service worker registration=] and its [=service worker registration/scope url=]. + 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 "[=html/serviceworker=]".
- + + + A serviceworker link can be declared using a `Link` header [[!RFC5988]] with "`serviceworker`" as the value of the "`rel`" parameter and a [=service worker/script url=] as the target IRI, and the following optional target attributes: + + : `scope` + :: Value: A [=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 [[!RFC5988]] processes a Link header that contains a serviceworker link, the user agent *should* run these steps: @@ -1768,7 +1795,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
- + 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}> or <{link/scope}> attributes of the <{link}> element of a serviceworker link is changed, the user agent *should* run these steps: @@ -1778,8 +1805,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe 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 <{link/workertype}> attribute, or "classic" if the <{link/workertype}> attribute is omitted. - 1. If |workerType| is not a valid {{WorkerType}} value, queue a task to fire an event named error at the <{link}> element, and abort these steps. + 1. Let |workerType| be the state of the <{link/workertype}> attribute. 1. Let |useCache| be true if the <{link}> element has a <{link/usecache}> attribute, otherwise false. 1. Let |promise| be a new promise. 1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, |promise|, |client|, |client|'s creation URL, |workerType|, and |useCache|. @@ -1811,24 +1837,6 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
- -
- - -
-      partial interface HTMLLinkElement {
-        [CEReactions] attribute USVString scope;
-        [CEReactions] attribute WorkerType workerType;
-        [CEReactions] attribute boolean useCache;
-      };
-    
- - The scope IDL attribute must reflect the element's scope content attribute. - - The workerType IDL attribute must reflect the element's workertype content attribute. - - The useCache IDL attribute must reflect the element's usecache content attribute. -
diff --git a/docs/index.html b/docs/index.html index 198c10bc..812f4b5d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1425,7 +1425,7 @@

Service Workers Nightly

-

Editor’s Draft,

+

Editor’s Draft,

This version: @@ -1615,9 +1615,9 @@

Table of Contents

  • 5 Link type "serviceworker"
      -
    1. 5.1 Processing the Link header -
    2. 5.2 Processing the link element -
    3. 5.3 Link element interface extensions +
    4. 5.1 Declaring a "serviceworker" Link header +
    5. 5.2 Processing a "serviceworker" Link header +
    6. 5.3 Processing a "serviceworker" link element
  • 6 Caches @@ -1856,12 +1856,12 @@

    Bootstrapping with a service worker:
    // scope defaults to the path the script sits in
     // "/" in this example
    -navigator.serviceWorker.register("/serviceworker.js").then(registration => {
    +navigator.serviceWorker.register("/serviceworker.js").then(registration => {
       console.log("success!");
       if (registration.installing) {
         registration.installing.postMessage("Howdy from your installing page.");
       }
    -}, err => {
    +}, err => {
       console.error("Installing the worker failed!", err);
     });
     
    @@ -2390,10 +2390,10 @@

    Serving Cached Resources:
    // caching.js
    -self.addEventListener("install", event => {
    +self.addEventListener("install", event => {
       event.waitUntil(
         // Open a cache of resources.
    -    caches.open("shell-v1").then(cache => {
    +    caches.open("shell-v1").then(cache => {
           // Begins the process of fetching them.
           // The coast is only clear when all the resources are ready.
           return cache.addAll([
    @@ -2407,16 +2407,16 @@ 

    ); }); -self.addEventListener("fetch", event => { +self.addEventListener("fetch", event => { // No "fetch" events are dispatched to the service worker until it // successfully installs and activates. // All operations on caches are async, including matching URLs, so we use // promises heavily. e.respondWith() even takes promises to enable this: event.respondWith( - caches.match(e.request).then(response => { + caches.match(e.request).then(response => { return response || fetch(e.request); - }).catch(() => { + }).catch(() => { return caches.match("/fallback.html"); }) ); @@ -3631,10 +3631,31 @@

    -

    The serviceworker keyword may be used with link elements. This keyword creates an external resource link (serviceworker link) that is used to declare a service worker registration and its scope url.

    +

    A service worker registration and its scope url are created by a serviceworker link, which is declared using a "serviceworker" Link header or a link element whose rel attribute contains the keyword "serviceworker".

    - -

    When a user agent that supports [RFC5988] processes a Link header that contains a serviceworker link, the user agent should run these steps:

    + +

    A serviceworker link can be declared using a Link header [RFC5988] with "serviceworker" as the value of the "rel" parameter and a script url as the target IRI, and the following optional target attributes:

    +
    +
    scope +
    +

    Value: A scope url.

    +
    workertype +
    +

    Value: A worker type.

    +
    updateviacache +
    +

    Value: An 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 [RFC5988] 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.

      @@ -3663,8 +3684,8 @@
    - -

    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 href or scope attributes of the link element of a serviceworker link is changed, the user agent should run these steps:

    + +

    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 href or scope attributes of the link element of a serviceworker link is changed, the user agent should run these steps:

    1. If the href attribute is the empty string, abort these steps.

      @@ -3677,13 +3698,11 @@
    -

    The serviceworker link element must not delay the load event of the element’s node document.

    +

    The serviceworker link element must not 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="/">
    +
    <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: "/" });
     
    -
    - -
    partial interface HTMLLinkElement {
    -  [CEReactions] attribute USVString scope;
    -  [CEReactions] attribute WorkerType workerType;
    -  [CEReactions] attribute boolean useCache;
    -};
    -
    -

    The scope IDL attribute must reflect the element’s scope content attribute.

    -

    The workerType IDL attribute must reflect the element’s workertype content attribute.

    -

    The useCache IDL attribute must reflect the element’s usecache content attribute.

    -

    6. Caches

    @@ -4563,7 +4570,7 @@

    Appendix A: Algorithms

    The following definitions are the user agent’s internal data structures used throughout the specification.

    -

    A scope to registration map is an ordered map where the keys are scope urls and the values are service worker registrations.

    +

    A scope to registration map is an ordered map where the keys are scope urls and the values are service worker registrations.

    A job is an abstraction of one of register, update, and unregister request for a service worker registration.

    A job has a job type, which is one of register, update, and unregister. @@ -4584,7 +4591,7 @@

    Appendix A: Al
  • For unregister jobs, their scope url is the same.

    -

    A job queue is a thread safe queue used to synchronize the set of concurrent jobs. The job queue contains jobs as its elements. The job queue should satisfy the general properties of FIFO queue. A user agent must maintain a separate job queue for each service worker registration keyed by its scope url. A job queue is initially empty. Unless stated otherwise, the job queue referenced from the algorithm steps is a job queue for the job’s scope url.

    +

    A job queue is a thread safe queue used to synchronize the set of concurrent jobs. The job queue contains jobs as its elements. The job queue should satisfy the general properties of FIFO queue. A user agent must maintain a separate job queue for each service worker registration keyed by its scope url. A job queue is initially empty. Unless stated otherwise, the job queue referenced from the algorithm steps is a job queue for the job’s scope url.

    Create Job

    @@ -4759,7 +4766,7 @@

    referrer, a URL

    -

    workerType, a worker type

    +

    workerType, a worker type

    useCache, a boolean

    Output @@ -4785,7 +4792,7 @@

  • Let job be the result of running Create Job with register, scopeURL, scriptURL, promise, and client.

  • -

    Set job’s worker type to workerType.

    +

    Set job’s worker type to workerType.

  • Set job’s use cache to useCache.

  • @@ -4839,7 +4846,7 @@

    Let newestWorker be the result of running the Get Newest Worker algorithm passing registration as the argument.

  • -

    If newestWorker is not null, job’s script url equals newestWorker’s script url with the exclude fragments flag set, and job’s use cache's value equals registration’s use cache's value, then:

    +

    If newestWorker is not null, job’s script url equals newestWorker’s script url with the exclude fragments flag set, and job’s use cache's value equals registration’s use cache's value, then:

    1. Invoke Resolve Job Promise with job and the ServiceWorkerRegistration object which represents registration.

      @@ -4881,7 +4888,7 @@

      Let newestWorker be the result of running Get Newest Worker algorithm passing registration as the argument.

    2. -

      If job’s job type is update, and newestWorker’s script url does not equal job’s script url with the exclude fragments flag set, then:

      +

      If job’s job type is update, and newestWorker’s script url does not equal job’s script url with the exclude fragments flag set, then:

      1. Invoke Reject Job Promise with job and a TypeError.

        @@ -4893,7 +4900,7 @@

        Let referrerPolicy be the empty string.

      2. -

        Switching on job’s worker type, run these substeps with the following options:

        +

        Switching on job’s worker type, run these substeps with the following options:

        "classic"
        @@ -4951,7 +4958,7 @@

        Asynchronously complete these steps with a network error.

    3. -

      Let scopeURL be registration’s scope url.

      +

      Let scopeURL be registration’s scope url.

    4. Let maxScopeString be null.

    5. @@ -4998,7 +5005,7 @@

      Else, continue the rest of these steps after the algorithm’s asynchronous completion, with script being the asynchronous completion value.

    6. -

      If newestWorker is not null, newestWorker’s script url equals job’s script url with the exclude fragments flag set, 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 record's [[ECMAScriptCode]] is a byte-for-byte match with newestWorker’s script resource's module record's [[ECMAScriptCode]] otherwise, then:

      +

      If newestWorker is not null, newestWorker’s script url equals job’s script url with the exclude fragments flag set, 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 record's [[ECMAScriptCode]] is a byte-for-byte match with newestWorker’s script resource's module record's [[ECMAScriptCode]] otherwise, then:

      1. Invoke Resolve Job Promise with job and the ServiceWorkerRegistration object which represents registration.

        @@ -5013,7 +5020,7 @@

        Generate a unique opaque string and set worker’s id to the value.

      2. -

        Set worker’s script url to job’s script url, worker’s script resource to script, and worker’s type to job’s worker type.

        +

        Set worker’s script url to job’s script url, worker’s script resource to script, and worker’s type to job’s worker type.

      3. Set worker’s script resource’s HTTPS state to httpsState.

      4. @@ -5055,9 +5062,9 @@

        If newestWorker is null, abort these steps.

      5. -

        Let job be the result of running Create Job with update, registration’s scope url, newestWorker’s script url, null, and null.

        +

        Let job be the result of running Create Job with update, registration’s scope url, newestWorker’s script url, null, and null.

      6. -

        Set job’s worker type to newestWorker’s type.

        +

        Set job’s worker type to newestWorker’s type.

      7. Set job’s force bypass cache flag if its force bypass cache flag is set.

      8. @@ -5092,7 +5099,7 @@

        Invoke Resolve Job Promise with job and the ServiceWorkerRegistration object which represents registration.

      9. -

        Queue a task to fire an event named updatefound at all the ServiceWorkerRegistration objects for all the service worker clients whose creation URL matches registration’s scope url and all the service workers whose containing service worker registration is registration.

        +

        Queue a task to fire an event named updatefound at all the ServiceWorkerRegistration objects for all the service worker clients whose creation URL matches registration’s scope url and all the service workers whose containing service worker registration is registration.

      10. Let installingWorker be registration’s installing worker.

      11. @@ -5186,7 +5193,7 @@

        Run the Update Worker State algorithm passing registration’s active worker and activating as the arguments.

        Note: Once an active worker is activating, neither a runtime script error nor a force termination of the active worker prevents the active worker from getting activated.

      12. -

        For each service worker client client whose creation URL matches registration’s scope url:

        +

        For each service worker client client whose creation URL matches registration’s scope url:

        1. If client is a window client, unassociate client’s responsible document from its application cache, if it has one.

          @@ -5305,7 +5312,7 @@

          The API base URL
          -

          Return serviceWorker’s script url.

          +

          Return serviceWorker’s script url.

          The origin

          Return its registering service worker client's origin.

          @@ -5317,7 +5324,7 @@

          HTTPS state.

  • -

    Set workerGlobalScope’s url to serviceWorker’s script url.

    +

    Set workerGlobalScope’s url to serviceWorker’s script url.

  • Set workerGlobalScope’s HTTPS state to serviceWorker’s script resource’s HTTPS state.

  • @@ -5916,7 +5923,7 @@

    Let scopeString be serialized scope with the exclude fragment flag set.

  • -

    Let registration be a new service worker registration whose scope url is set to scope and use cache is set to useCache.

    +

    Let registration be a new service worker registration whose scope url is set to scope and use cache is set to useCache.

  • Set scope to registration map[scopeString] to registration.

  • @@ -5967,7 +5974,7 @@

    Update Registration State algorithm passing registration, "active" and null as the arguments.

  • -

    Let scopeString be serialized registration’s scope url with the exclude fragment flag set.

    +

    Let scopeString be serialized registration’s scope url with the exclude fragment flag set.

  • Remove scope to registration map[scopeString].

    @@ -6555,14 +6562,14 @@

    `Service-Worker-Allowed`
    -

    Indicates the user agent will override the path restriction, which limits the maximum allowed scope url that the script can control, to the given value.

    +

    Indicates the user agent will override the path restriction, which limits the maximum allowed scope url that the script can control, to the given value.

    Note: The value is a URL. If a relative URL is given, it is parsed against the script’s URL.

  • Default scope:
    // Maximum allowed scope defaults to the path the script sits in
     // "/js" in this example
    -navigator.serviceWorker.register("/js/sw.js").then(() => {
    +navigator.serviceWorker.register("/js/sw.js").then(() => {
       console.log("Install succeeded with the default scope '/js'.");
     });
     
    @@ -6571,7 +6578,7 @@

    Upper path without Service-Worker-Allowed header:
    // Set the scope to an upper path of the script location
     // Response has no Service-Worker-Allowed header
    -navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).catch(() => {
    +navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).catch(() => {
       console.error("Install failed due to the path restriction violation.");
     });
     
    @@ -6580,7 +6587,7 @@

    Upper path with Service-Worker-Allowed header:
    // Set the scope to an upper path of the script location
     // Response included "Service-Worker-Allowed : /"
    -navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).then(() => {
    +navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).then(() => {
       console.log("Install succeeded as the max allowed scope was overriden to '/'.");
     });
     
    @@ -6589,7 +6596,7 @@

    A path restriction voliation even with Service-Worker-Allowed header:
    // Set the scope to an upper path of the script location
     // Response included "Service-Worker-Allowed : /foo"
    -navigator.serviceWorker.register("/foo/bar/sw.js", { scope: "/" }).catch(() => {
    +navigator.serviceWorker.register("/foo/bar/sw.js", { scope: "/" }).catch(() => {
       console.error("Install failed as the scope is still out of the overriden maximum allowed scope.");
     });
     
    @@ -6976,8 +6983,6 @@

    attribute for ServiceWorkerRegistration, in §3.2.5
  • dict-member for RegistrationOptions, in §3.4 -
  • attribute for HTMLLinkElement, in §5.3 -
  • element-attr for link, in §5.3
  • scopes, in §4.5
  • scope to registration map, in §Unnumbered section @@ -7018,7 +7023,6 @@

    ServiceWorkerGlobalScope, in §4.1
  • Service Worker Has No Pending Events, in §Unnumbered section
  • serviceworker link, in §5 -
  • serviceworker link type, in §5
  • ServiceWorkerRegistration, in §3.2
  • service worker registration @@ -7087,13 +7091,11 @@

    dfn for service worker registration, in §2.2
  • dfn for job, in §Unnumbered section -
  • usecache, in §5.3
  • useCache
  • used, in §2.4
  • uses, in §2.4 @@ -7116,8 +7118,6 @@

    worker, in §4.3
  • "worker", in §4.3
  • worker client, in §2.3 -
  • workertype, in §5.3 -
  • workerType, in §5.3
  • worker type, in §Unnumbered section

    Terms defined by reference

    @@ -7146,7 +7146,6 @@

    fire an event
  • in a document tree
  • node document -
  • reflect
  • stop immediate propagation flag
  • stop propagation flag
  • type @@ -7247,11 +7246,9 @@

    [HTML] defines the following terms:
  • [INFRA] defines the following terms: @@ -7406,6 +7407,7 @@

  • context iri
  • target attribute +
  • target attributes
  • target iri
  • @@ -7724,12 +7726,6 @@

    I sequence<MessagePort> ports = []; }; -partial interface HTMLLinkElement { - [CEReactions] attribute USVString scope; - [CEReactions] attribute WorkerType workerType; - [CEReactions] attribute boolean useCache; -}; - partial interface WindowOrWorkerGlobalScope { [SecureContext, SameObject] readonly attribute CacheStorage caches; }; @@ -7843,10 +7839,11 @@

    3.1.1. scriptURL
  • 3.2.7. update() -
  • Register -
  • Update (2) (3) -
  • Soft Update -
  • Run Service Worker (2) +
  • 5.1. Declaring a "serviceworker" Link header +
  • Register +
  • Update (2) (3) +
  • Soft Update +
  • Run Service Worker (2) @@ -9416,44 +9414,9 @@

    #dfn-serviceworker-linkReferenced in: - - - - - - -