diff --git a/source b/source index aa6cf8a37e6..f082fef67d9 100644 --- a/source +++ b/source @@ -2529,6 +2529,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • `Cross-Origin-Resource-Policy` header
  • process response
  • getting a structured field value
  • +
  • header list
  • set
  • get, decode, and split
  • terminate
  • @@ -2542,6 +2543,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • incrementally reading a body
  • processResponseConsumeBody
  • processResponseEndOfBody
  • +
  • processEarlyHintsResponse
  • response and its @@ -14301,11 +14303,18 @@ interface HTMLLinkElement : HTMLElement {
    Processing `Link` headers
    -

    To process link headers given a Document doc, a response response, and a "pre-media" or "media" phase:

    +

    The processing of `Link` headers apart from preload, in particular their influence on a Document's + script-blocking style sheet counter, is not defined. See issue #4224 for discussion on integrating + this into the spec.

    + +

    To extract links from headers given + header list headers:

      +
    1. Let links be a new list.

    2. +
    3. Let rawLinkHeaders be the result of getting, decoding, and splitting `Link` from response's HTMLLinkElement : HTMLElement {

    4. Let linkObject be the result of parsing linkHeader.

    5. -
    6. -

      If linkObject["relation_type"] is not "preload", then continue.

      +
    7. If linkObject["relation_type"] is not "preload", then continue.

    8. -

      Support for additional link types can be added here in the future.

      - +
    9. If linkObject["target_uri"] does not + exist, then continue.

    10. -
    11. Let attribs be linkObject["target_attributes"].

    12. +
    13. Append linkObject to + links.

    14. +
    +
  • +
  • Return links.

  • + + +

    To process link headers given a Document doc, + a response response, and a + "pre-media" or "media" phase:

    + +
      +
    1. Let links be the result of + extracting links from response's + header list.

    2. + +
    3. +

      For each linkObject in links:

      + +
        +
      1. Let attribs be + linkObject["target_attributes"].

      2. Let expectedPhase be "media" if either "srcset", "imagesrcset", or "media" exist in - attribs; otherwise false.

      3. + attribs; otherwise "pre-media".

      4. If expectedPhase is not phase, then continue.

      5. -
      6. If params includes "media" and - params["media"] does not match the environment, then +

      7. If attribs["media"] exists and attribs["media"] + does not match the environment, then continue.

      8. Let element be the result of creating an @@ -14373,11 +14401,206 @@ interface HTMLLinkElement : HTMLElement {

      -

      The processing of `Link` headers apart from preload, in particular their influence on a Document's - script-blocking style sheet counter, is not defined. See issue #4224 for discussion on integrating - this into the spec.

      +
      Early hints
      + +

      Early hints allow user-agents to perform some operations, such as to speculatively + load resources that are likely to be used by the document, before the navigation request is fully + handled by the server and a response code is served. Servers can indicate early hints by serving a + response with a 103 status code before serving the final + response.

      + +
      +

      For example, given the following sequence of responses:

      +
      103 Early Hint
      +Link: </image.png>; rel=preload; as=image
      + +
      200 OK
      +Content-Type: text/html
      +
      +<!DOCTYPE html>
      +...
      +<img src="/image.png">
      + +

      the image will start loading before the HTML content arrives.

      +
      + +

      Only the first early hint response served during the navigation is handled, and it + is discarded if it is succeeded by a cross-origin redirect.

      + +

      In addition to the `Link` headers, it is possible that the 103 + response contains a Content Security Policy header, which is enforced when processing + the early hint.

      + +
      +

      For example, given the following sequence of responses:

      +
      103 Early Hint
      +Content-Security-Policy: style-src: self;
      +Link: </style.css>; rel=preload; as=style
      + +
      103 Early Hint
      +Link: </image.png>; rel=preload; as=image
      + +
      302 Redirect
      +Location: /alternate.html
      + +
      200 OK
      +Content-Security-Policy: style-src: none;
      +Link: </font.ttf>; rel=preload; as=font
      + +

      The font and style would be loaded, and the image will be discarded, as only the first early + hint response in the final redirect chain is respected. The late Content Security + Policy header comes after the request to fetch the style has already been performed, but + the style will not be accessible to the document.

      +
      + + +

      To process early hint headers given a response response and an environment + reservedEnvironment:

      + +

      Early-hint `Link` headers are always processed + before `Link` headers from the final response, followed by link elements. This is + equivalent to prepending the contents of the early and final `Link` headers to the Document's head element, + in respective order.

      + +
        +
      1. +

        Let earlyPolicyContainer be the result of creating a policy container from + a fetch response given response and reservedEnvironment.

        + +

        This allows the early hint response to + include a Content Security Policy which would be enforced when fetching the early hint request.

        +
      2. + +
      3. Let links be the result of extracting links from response's header list.

      4. + +
      5. Let uncommittedPreloads be an empty list.

      6. + +
      7. +

        For each linkObject in links:

        + +

        The moment we receive the early hint link header, we begin fetching earlyRequest. If it comes back before the + Document is created, we set earlyResponse to the response of that fetch and + once the Document is created we commit it (by making it available in the map + of preloaded resources as if it was a link element). If the + Document is created first, the response is + committed as soon as it becomes available.

        + +
          +
        1. +

          Let attribs be linkObject["target_attributes"].

          + +

          Only the as, crossorigin, and integrity attributes are handled as part of early hint + processing. The other ones, in particular media, imagesrcset, imagesizes, and "blocking" are + only applicable once a Document is created.

          +
        2. + +
        3. If attribs["as"] does not exist, then continue.

        4. + +
        5. Let destination be attribs["as"].

        6. + +
        7. Let crossorigin be attribs["crossorigin"] if attribs["crossorigin"] exists, + or the empty string otherwise.

        8. + +
        9. If destination is not a destination, continue.

        10. + +
        11. Let url be the result of parsing + linkObject["target_uri"] relative to response's + URL.

        12. + +
        13. Let earlyRequest be the result of creating a potential-CORS request given url, + destination, and crossorigin.

        14. + +
        15. Set earlyRequest's policy + container to earlyPolicyContainer.

        16. + +
        17. If attribs["integrity"] exists, then set earlyRequest's integrity metadata to + attribs["integrity"].

        18. + +
        19. Let unsafeEndTime be 0.

        20. + +
        21. Let earlyResponse be null.

        22. + +
        23. Let processResponse given response + res be to set earlyResponse to res.

        24. + +
        25. +

          Append the following steps given Document + document to uncommittedPreloads:

          + +
            +
          1. Let entry be new preload entry whose response.

          2. + +
          3. +

            Let respond be the following steps given response response:

            + +
              +
            1. Finalize and report timing given response, + document's relevant global object, "early-hint", and unsafeEndTime.

            2. + +
            3. If entry's on response + available is null, then set entry's response to response; otherwise call entry's on response available given + response.

            4. +
            +
          4. + +
          5. Let preloadedResources be document's map of preloaded + resources.

          6. + +
          7. Let key be the result of creating a + preload key given earlyRequest.

          8. + +
          9. If preloadedResources[key] exists, then set preloadedResources[key]'s response to response; otherwise, set preloadedResources[key] to a new + preload entry whose response is + response.

          10. +
          +
        26. + +
        27. If earlyResponse is null, then set processResponse to + respond; otherwise call respond with earlyResponse.

        28. + +
        29. Preload earlyRequest with the + following steps given response res: set + unsafeEndTime to the unsafe shared current time and call + processResponse with res.

        30. +
        +
      8. + +
      9. Return uncommittedPreloads.

      10. +
      @@ -25847,6 +26070,44 @@ document.body.appendChild(wbr);
    4. Return true.

    +

    To preload a resource given a request + request and processResponse, which is an algorithm accepting a response: fetch + request, with processResponseConsumeBody + set to the following steps given response + response and null or byte sequence bytesOrNull:

    + +
      +
    1. +

      If bytesOrNull is a byte sequence, then set response's + body to the first return value of safely extracting bytesOrNull.

      + +

      By using processResponseConsumeBody, + we have extracted the entire body. This is necessary to ensure the preloader loads the + entire body from the network, regardless of whether the preload will be consumed (which is + uncertain at this point). This step then resets the request's body to a new body containing the + same bytes, so that other specifications can read from it at the time of actual consumption, + despite us having already done so once.

      +
    2. + +
    3. Otherwise, set response to a network error.

    4. + +
    5. Call processResponse with response.

      +
    + +

    To create a preload key for a request + request, return a new preload key whose URL is request's URL, destination is request's destination, integrity metadata is request's integrity metadata, mode is request's mode, and + credentials mode is request's credentials mode.

    +

    The fetch and process the linked resource steps for this type of linked resource, given a link element el, are:

    @@ -25882,15 +26143,8 @@ document.body.appendChild(wbr); -
  • Let preloadKey be a preload key whose URL is request's URL, destination is request's destination, integrity metadata is request's integrity metadata, mode is request's mode, and - credentials mode is request's credentials mode.

  • +
  • Let preloadKey be the result of creating a + preload key given request.

  • Let preloadEntry be a new preload entry.

  • @@ -25901,42 +26155,24 @@ document.body.appendChild(wbr); on el.

  • -

    Fetch request, with processResponseConsumeBody set to the following steps - given response response and null or byte - sequence bytesOrNull:

    +

    Preload request, with the following + steps given response response:

      -
    1. -

      If bytesOrNull is a byte sequence, then set response's - body to the first return value of safely extracting bytesOrNull.

      - -

      By using processResponseConsumeBody, - we have extracted the entire body. This is necessary to ensure the preloader loads - the entire body from the network, regardless of whether the preload will be consumed (which - is uncertain at this point). This step then resets the request's body to a new body - containing the same bytes, so that other specifications can read from it at the time of - actual consumption, despite us having already done so once.

      -
    2. - -
    3. Otherwise, set response to a network error.

    4. -
    5. Finalize and report timing with response, given el's relevant global object and "link".

    6. -
    7. Fire an event named load at el.

    8. - -
    9. Unblock rendering on el.

    10. -
    11. If preloadEntry's on response available is null, then set preloadEntry's response to response.

    12. Otherwise, call preloadEntry's on response available with response.

    13. + +
    14. Fire an event named load at el.

    15. + +
    16. Unblock rendering on el.

  • @@ -88096,6 +88332,10 @@ interface Location { // but see also unsafe start time
    a number, representing a value of the unsafe shared current time when the navigation has started
    + +
    uncommitted preloads
    +
    null or a list of algorithms representing early preloaded links, to be committed + once the document has been created

    Once a navigation params struct is created, this standard does not @@ -88404,9 +88644,10 @@ interface Location { // but see also process response end of body is processResponseEndOfBody, unsafe start time is - unsafeNavigationStartTime, and unsafeNavigationStartTime, has cross-origin redirects is - false.

    + false, and uncommitted preloads is null.

  • Run process a navigate response with navigationType, allowedToDownload, hasTransientActivation, and @@ -88466,9 +88707,10 @@ interface Location { // but see also process response end of body is processResponseEndOfBody, unsafe start time is - unsafeNavigationStartTime, and unsafeNavigationStartTime, has cross-origin redirects is - false.

  • + false, and uncommitted preloads is null.

  • Run process a navigate response with navigationType, allowedToDownload, hasTransientActivation, and @@ -88584,6 +88826,8 @@ interface Location { // but see also

    Set request's reserved client to null.

  • + +
  • +

    Set uncommittedPreloads to null.

    + +

    Preloaded links from early hint + headers remain in the preload cache after a same origin redirect, but + get discarded when the redirect is cross-origin.

    +
  • @@ -88669,7 +88921,13 @@ interface Location { // but see also
    fetch request.

    + data-x="concept-fetch">fetch request, with + processEarlyHintsResponse set to the following step + given a response earlyResponse: If + uncommittedPreloads is null, then set uncommittedPreloads to the result + of processing early hint headers given + earlyResponse and request's + reserved client.

  • Otherwise, perform HTTP-redirect fetch using request and response.

  • @@ -88808,9 +89066,11 @@ interface Location { // but see also
    process response end of body is processResponseEndOfBody, unsafe - start time is unsafeNavigationStartTime, and has cross-origin redirects is - hasCrossOriginRedirects.

    + start time is unsafeNavigationStartTime, + has cross-origin redirects is + hasCrossOriginRedirects, and + uncommitted preloads is + uncommittedPreloads.

  • Run process a navigate response with navigationType, allowedToDownload, hasTransientActivation, and @@ -89407,6 +89667,10 @@ interface Location { // but see also issue #2900.

  • +
  • For each commitEarlyPreload in + navigationParams's uncommitted + preloads, call commitEarlyPreload given document.

    +
  • Process link headers given document, navigationParams's response, and "pre-media".

  • @@ -127282,6 +127546,9 @@ INSERT INTERFACES HERE
    [RFC7578]
    Returning Values from Forms: multipart/form-data, L. Masinter. IETF.
    +
    [RFC8297]
    +
    An HTTP Status Code for Indicating Hints, K. Oku. IETF.
    +
    [SCREENORIENTATION]
    Screen Orientation API, M. Lamouri, M. Cáceres. W3C.