Skip to content

Commit 3b32836

Browse files
committed
Process Preload link headers
Preload links based on link headers, some of them on document creation, and the rest (viewport-dependant ones) when response chunks start arriving. This can be used as an infra for early-hints and other link types. Conforms to the current common denominator of implementations. See #4224
1 parent 5b01d31 commit 3b32836

File tree

1 file changed

+77
-15
lines changed

1 file changed

+77
-15
lines changed

source

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14239,20 +14239,72 @@ interface <dfn interface>HTMLLinkElement</dfn> : <span>HTMLElement</span> {
1423914239

1424014240
<h5>Processing `<code data-x="http-link">Link</code>` headers</h5>
1424114241

14242-
<p>HTTP `<code data-x="http-link">Link</code>` headers, if supported, must be assumed to come
14243-
before any links in the document, in the order that they were given in the HTTP message. These
14244-
headers are to be processed according to the rules given in the relevant specifications. <ref
14245-
spec=HTTP> <ref spec=WEBLINK></p> <!-- WEBLINK is ref for Link: header -->
14246-
14247-
<p class="note">Registration of relation types in HTTP `<code data-x="http-link">Link</code>`
14248-
headers is distinct from <a href="#linkTypes">HTML link types</a>, and thus their semantics can be
14249-
different from same-named HTML types.</p>
14250-
14251-
<p class="XXX">The processing of `<code data-x="http-link">Link</code>` headers, in particular
14252-
their influence on a <code>Document</code>'s <span>script-blocking style sheet counter</span>, is
14253-
not defined. See <a href="https://github.com/whatwg/html/issues/4224">issue #4224</a> for
14254-
discussion on integrating this into the spec.</p>
14242+
<p>To <dfn>process link headers</dfn> given <code>Document</code> <var>doc</var>,
14243+
<span data-x="concept-response">response</span>, and a "<code data-x="">pre-media</code>" or
14244+
"<code data-x="">media</code>" <var>phase</var>:</p>
14245+
14246+
<ol>
14247+
<li><p>Let <var>linkHeaders</var> be the result of <span>getting a structured field value</span>
14248+
given `<code>Link</code>` and "<code data-x="">list</code>" from
14249+
<var>response</var>'s <span data-x="concept-response-header-list">header list</span>.</p></li>
14250+
14251+
<li><p>If <var>linkHeaders</var> is null, then return.</p></li>
14252+
14253+
<li>
14254+
<p><span data-x="list iterate">For each</span> <var>rawLink</var> of
14255+
<var>linkHeaders</var>, run these steps:</p>
1425514256

14257+
<ol>
14258+
<li><p>Let (<var>href</var>, <var>params</var>) be the result of parsing
14259+
<var>linkHeader</var> according to the `<code data-x="http-link">Link</code>` header
14260+
Serialization rules. <ref spec=HTTP> <ref spec=WEBLINK></p></li>
14261+
<!-- WEBLINK is ref for Link: header -->
14262+
14263+
<li>
14264+
<p>If <var>params</var>["<code data-x="attr-link-rel">rel</code>"] is
14265+
"<code data-x="rel-preload">preload</code>", then abort these steps.</p>
14266+
14267+
<p class=note>Additional support for link types can be added here in the future.</p>
14268+
</li>
14269+
14270+
<li><p>Let <var>expectedPhase</var> be "<code data-x="">media</code>" if either
14271+
"<code data-x="attr-img-srcset">srcset</code>",
14272+
"<code data-x="attr-link-imagesrcset">imagesrcset</code>", or <code
14273+
data-x="attr-link-media">media</code>" <span data-x="map exists">exist</span> in
14274+
<var>params</var>; Otherwise false.</p></li>
14275+
14276+
<li><p>If <var>expectedPhase</var> is not <var>phase</var>, then abort these
14277+
steps.</p></li>
14278+
14279+
<li><p>If <var>params</var> includes "<code data-x="attr-link-media">media</code>" and
14280+
<var>params</var>["<code data-x="attr-link-media">media</code>"] does not
14281+
<span data-x="matches the environment">match the environment</span>, then abort these
14282+
steps.</p></li>
14283+
14284+
<li><p>Let <var>element</var> be the result of
14285+
<span data-x="create an element">creating an element</span> given <var>document</var>,
14286+
<code>link</code>, and the <span>HTML namespace</span>.</p></li>
14287+
14288+
<li><p><span data-x="map iterate">For each</span> <var>entry</var> in <var>params</var>: If
14289+
<var>entry</var>[0] is "<code data-x="attr-link-as">as</code>",
14290+
"<code data-x="attr-img-srcset">rel</code>", "<code data-x="attr-link-type">type</code>",
14291+
"<code data-x="attr-link-crossorigin">crossorigin</code>",
14292+
"<code data-x="attr-link-imagesizes">imagesizes</code>",
14293+
"<code data-x="attr-link-imagesrcset">imagesrcset</code>", or
14294+
"<code data-x="attr-link-media">media</code>", then <span data-x="list append">append</span>
14295+
<var>entry</var> to <var>element</var>'s <span>attribute list</span>.</p></li>
14296+
14297+
<li><p><span data-x="fetch and process the linked resource">Fetch and process</span>
14298+
<var>el</var>.</p></li>
14299+
</ol>
14300+
</li>
14301+
</ol>
14302+
14303+
<p class="XXX">The processing of additional `<code data-x="http-link">Link</code>` headers, in
14304+
particular their influence on a <code>Document</code>'s
14305+
<span>script-blocking style sheet counter</span>, is not defined. See
14306+
<a href="https://github.com/whatwg/html/issues/4224">issue #4224</a> for
14307+
discussion on integrating this into the spec.</p>
1425614308

1425714309
</div>
1425814310

@@ -88778,7 +88830,7 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
8877888830
data-x="navigation-params-response">response</span>'s <span
8877988831
data-x="concept-response-service-worker-timing-info">service worker timing info</span>.</p></li>
8878088832

88781-
<li>
88833+
<li>
8878288834
<p>If <var>navigationParams</var>'s <span data-x="navigation-params-response">response</span>
8878388835
has a `<code>Refresh</code>` header, then:</p>
8878488836

@@ -88795,6 +88847,10 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
8879588847
href="https://github.com/whatwg/html/issues/2900">issue #2900</a>.</p>
8879688848
</li>
8879788849

88850+
<li><p><span>Process link headers</span> given <var>document</var>, <var>navigationParams</var>'s
88851+
<span data-x="navigation-params-response">response</span>, and
88852+
"<code data-x="">pre-media</code>".</p></li>
88853+
8879888854
<li><p>Return <var>document</var>.</p></li>
8879988855
</ol>
8880088856

@@ -89008,12 +89064,18 @@ new PaymentRequest(&hellip;); // Allowed to use
8900889064
<var>navigationParams</var>.</p></li>
8900989065

8901089066
<li>
89011-
<p>Create an <span>HTML parser</span> and associate it with the <var>document</var>. Each
89067+
<p>Create an <span>HTML parser</span> and associate it with the <var>document</var>. Each
8901289068
<span data-x="concept-task">task</span> that the <span>networking task source</span> places on
8901389069
the <span>task queue</span> while fetching runs must then fill the parser's <span>input byte
8901489070
stream</span> with the fetched bytes and cause the <span>HTML parser</span> to perform the
8901589071
appropriate processing of the input stream.</p>
8901689072

89073+
<p>The first <span data-x="concept-task">task</span> that the
89074+
<span>networking task source</span> places on the <span>task queue</span> while fetching runs
89075+
must <li><p><span>process link headers</span> given <var>document</var>,
89076+
<var>navigationParams</var>'s <span data-x="navigation-params-response">response</span>, and
89077+
"<code data-x="">media</code>".</p>
89078+
8901789079
<p class="note">The <span>input byte stream</span> converts bytes into characters for use in the
8901889080
<span data-x="tokenization">tokenizer</span>. This process relies, in part, on character encoding
8901989081
information found in the real <span data-x="Content-Type">Content-Type metadata</span> of the

0 commit comments

Comments
 (0)