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
` headerLink
` headersTo 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:
Let links be a new list.
Let rawLinkHeaders be the result of getting, decoding, and splitting
` If linkObject[" If linkObject[" Support for additional link types can be added here in the future.Link
` from response's HTMLLinkElement : HTMLElement {
relation_type
"] is not "preload
", then continue.relation_type
"] is not "preload
", then continue.
If linkObject["target_uri
"] does not
+ exist, then continue.
Let attribs be linkObject["target_attributes
"].
Append linkObject to + links.
Return links.
To process link headers given a Document
doc,
+ a response response, and a
+ "pre-media
" or "media
" phase:
Let links be the result of + extracting links from response's + header list.
For each linkObject in links:
+ +Let attribs be
+ linkObject["target_attributes
"].
Let expectedPhase be "media
" if either "srcset
", "imagesrcset
", or "media
" exist in
- attribs; otherwise false.
pre-media
".If expectedPhase is not phase, then continue.
If params includes "media
" and
- params["media
"] does not match the environment, then
+
If attribs["media
"] exists and attribs["media
"]
+ does not match the environment, then
continue.
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 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.
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.
+Let links be the result of extracting links from response's header list.
Let uncommittedPreloads be an empty list.
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.
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.
If attribs["as
"] does not exist, then continue.
Let destination be attribs["as
"].
Let crossorigin be attribs["crossorigin
"] if attribs["crossorigin
"] exists,
+ or the empty string otherwise.
If destination is not a destination, continue.
Let url be the result of parsing
+ linkObject["target_uri
"] relative to response's
+ URL.
Let earlyRequest be the result of creating a potential-CORS request given url, + destination, and crossorigin.
Set earlyRequest's policy + container to earlyPolicyContainer.
If attribs["integrity
"] exists, then set earlyRequest's integrity metadata to
+ attribs["integrity
"].
Let unsafeEndTime be 0.
Let earlyResponse be null.
Let processResponse given response + res be to set earlyResponse to res.
Append the following steps given Document
+ document to uncommittedPreloads:
Let entry be new preload entry whose response.
Let respond be the following steps given response response:
+ +Finalize and report timing given response,
+ document's relevant global object, "early-hint
", and unsafeEndTime.
If entry's on response + available is null, then set entry's response to response; otherwise call entry's on response available given + response.
Let preloadedResources be document's map of preloaded + resources.
Let key be the result of creating a + preload key given earlyRequest.
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.
If earlyResponse is null, then set processResponse to + respond; otherwise call respond with earlyResponse.
Preload earlyRequest with the + following steps given response res: set + unsafeEndTime to the unsafe shared current time and call + processResponse with res.
Return uncommittedPreloads.
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:
+ +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.
+Otherwise, set response to a network error.
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:
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.
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:
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.
-Otherwise, set response to a network error.
Finalize and report timing with response, given el's
relevant global object and "link
".
Fire an event named load
at el.
Unblock rendering on el.
If preloadEntry's on response available is null, then set preloadEntry's response to response.
Otherwise, call preloadEntry's on response available with response.
Fire an event named load
at el.
Unblock rendering on el.
document
has been createdOnce 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.
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.
+Otherwise, perform HTTP-redirect fetch using request and response.
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
".