Skip to content

Commit

Permalink
Update <link>'s processing model to work well for preload
Browse files Browse the repository at this point in the history
This allows the preload spec to delegate to HTML's "obtain the resource"
algorithm for elements, instead of creating a copy of it. The
latter approach has been attempted, but got out of date very quickly;
see w3c/preload#91 for more details.

This also updates rel="preload" to account for recent changes to Fetch
that introduced the concept of a "potential destination" for use here.
See whatwg/fetch#547.

Notably, part of this integration is ignoring invalid as="" attributes,
which now includes empty ones. No error event is fired.

Finally, it also allows other specifications to override the delaying of
the load event, as the preload spec does.
  • Loading branch information
domenic committed Jun 2, 2017
1 parent df520f8 commit eb5d1cc
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2699,6 +2699,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x="concept-request-initiator" data-x-href="https://fetch.spec.whatwg.org/#concept-request-initiator">initiator</dfn></li>
<li><dfn data-x="concept-request-type" data-x-href="https://fetch.spec.whatwg.org/#concept-request-type">type</dfn></li>
<li><dfn data-x="concept-request-destination" data-x-href="https://fetch.spec.whatwg.org/#concept-request-destination">destination</dfn></li>
<li><dfn data-x="concept-potential-destination" data-x-href="https://fetch.spec.whatwg.org/#concept-potential-destination">potential destination</dfn></li>
<li><dfn data-x="concept-potential-destination-translate" data-x-href="https://fetch.spec.whatwg.org/#concept-potential-destination-translate">translating</dfn> a <span data-x="concept-potential-destination">potential destination</span></li>
<li><dfn data-x="concept-request-priority" data-x-href="https://fetch.spec.whatwg.org/#concept-request-priority">priority</dfn></li>
<li><dfn data-dfn-for="request" data-x="concept-request-origin" data-x-href="https://fetch.spec.whatwg.org/#concept-request-origin">origin</dfn></li>
<li><dfn data-x="concept-request-referrer" data-x-href="https://fetch.spec.whatwg.org/#concept-request-referrer">referrer</dfn></li>
Expand Down Expand Up @@ -13110,17 +13112,21 @@ interface <dfn>HTMLLinkElement</dfn> : <span>HTMLElement</span> {
<hr>

<p>The <dfn><code data-x="attr-link-as">as</code></dfn> attribute specifies the <span
data-x="concept-request-destination">destination</span> for a preload request for the resource
given by the <code data-x="attr-link-href">href</code> attribute. It is an <span>enumerated
attribute</span>. Each <span data-x="concept-request-destination">request destination</span>,
including the empty string, is a keyword for this attribute, mapping to a state of the same name.
The attribute's <i data-x="missing value default">missing value default</i> and <i data-x="invalid
value default">invalid value default</i> are both the empty string state. The attribute may be
omitted. The attribute must not be specified on <code>link</code> elements that do not have a
<code data-x="attr-link-rel">rel</code> attribute that contains the
<code data-x="rel-preload">preload</code> keyword.<span w-nodev> User agents must implement the
processing model of the <code data-x="attr-link-as">as</code> attribute described in
<cite>Preload</cite>. <ref spec=FETCH> <ref spec=PRELOAD></span></p>
data-x="concept-potential-destination">potential destination</span> for a preload request for the
resource given by the <code data-x="attr-link-href">href</code> attribute. It is an
<span>enumerated attribute</span>. Each <span data-x="concept-potential-destination">potential
destination</span> is a keyword for this attribute, mapping to a state of the same name. The
attribute must be specified on <code>link</code> elements that have a <code
data-x="attr-link-rel">rel</code> attribute that contains the <code
data-x="rel-preload">preload</code> keyword, but must not be specified on <code>link</code>
elements which do not. <span w-nodev>The processing model for how the <code
data-x="attr-link-as">as</code> attribute is used is given in the <span
data-x="concept-link-obtain">steps to obtain the resource</span>.</span></p>

<p class="note">The attribute does not have a <i data-x="missing value default">missing value
default</i> or <i data-x="invalid value default">invalid value default</i>, meaning that invalid
or missing values for the attribute map to no state. This is accounted for in the processing
model.</p>

<hr>

Expand Down Expand Up @@ -13327,6 +13333,22 @@ interface <dfn>HTMLLinkElement</dfn> : <span>HTMLElement</span> {
<code>link</code> element's <code data-x="attr-link-referrerpolicy">referrerpolicy</code>
attribute.</p></li>

<li>
<p>If the <code data-x="attr-link-rel">rel</code> attribute contains the <code
data-x="rel-preload">preload</code> keyword, then:</p>

<ol>
<li><p>Let <var>as</var> be the current state of the <code data-x="attr-link-as">as</code>
attribute.</p></li>

<li><p>If <var>as</var> is no state, then return.</p></li>

<li><p>Set <var>request</var>'s <span data-x="concept-request-destination">destination</span>
to the result of <span data-x="concept-potential-destination-translate">translating</span>
<var>as</var>.</p></li>
</ol>
</li>

<!--FETCH--><li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p></li>

</ol>
Expand All @@ -13353,10 +13375,11 @@ interface <dfn>HTMLLinkElement</dfn> : <span>HTMLElement</span> {
<p>The <span>task source</span> for these <span data-x="concept-task">tasks</span> is the
<span>DOM manipulation task source</span>.</p>

<p>The element must <span>delay the load event</span> of the element's <span>node document</span>
until all the attempts to obtain the resource and its <span>critical subresources</span> are
complete. (Resources that the user agent has not yet attempted to obtain, e.g. because it is
waiting for the resource to be needed, do not <span>delay the load event</span>.)</p>
<p>Unless otherwise specified for a given <code data-x="attr-link-rel">rel</code> keyword, the
element must <span>delay the load event</span> of the element's <span>node document</span> until
all the attempts to obtain the resource and its <span>critical subresources</span> are complete.
(Resources that the user agent has not yet attempted to obtain, e.g. because it is waiting for the
resource to be needed, do not <span>delay the load event</span>.)</p>

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

Expand Down Expand Up @@ -23357,7 +23380,7 @@ interface <dfn>HTMLHyperlinkElementUtils</dfn> {
<td><span data-x="external resource link">External Resource</span></td>
<td><em>not allowed</em></td>
<td class="yes"> Yes </td>
<td>Specifies that the user agent must preemptively <span data-x="concept-fetch">fetch</span> and cache the target resource for current <span data-x="navigate">navigation</span> according to the <span data-x="concept-request-destination">destination</span> given by the <code data-x="attr-link-as">as</code> attribute (and the <span data-x="concept-request-priority">priority</span> associated with that <span data-x="concept-request-destination">destination</span>).</td>
<td>Specifies that the user agent must preemptively <span data-x="concept-fetch">fetch</span> and cache the target resource for current <span data-x="navigate">navigation</span> according to the <span data-x="concept-potential-destination">potential destination</span> given by the <code data-x="attr-link-as">as</code> attribute (and the <span data-x="concept-request-priority">priority</span> associated with the <span data-x="concept-potential-destination-translate">corresponding</span> <span data-x="concept-request-destination">destination</span>).</td>
</tr>

<tr>
Expand Down Expand Up @@ -23996,13 +24019,15 @@ interface <dfn>HTMLHyperlinkElementUtils</dfn> {

<p>The <code data-x="rel-preload">preload</code> keyword indicates that the user agent must
preemptively <span data-x="concept-fetch">fetch</span> and cache the specified resource according
to the <span data-x="concept-request-destination">destination</span> given by the <code
data-x="attr-link-as">as</code> attribute (and the <span
data-x="concept-request-priority">priority</span> associated with that <span
to the <span data-x="concept-potential-destination">potential destination</span> given by the
<code data-x="attr-link-as">as</code> attribute (and the <span
data-x="concept-request-priority">priority</span> associated with the <span
data-x="concept-potential-destination-translate">corresponding</span> <span
data-x="concept-request-destination">destination</span>), as it is highly likely that the user
will require this resource for the current navigation. <span w-nodev>User agents must implement
the processing model of the <code data-x="rel-preload">preload</code> keyword described in
<cite>Preload</cite>.</span> <ref spec=PRELOAD></p>
<cite>Preload</cite>, as well as in this specification's <span data-x="concept-link-obtain">obtain
the resource</span> algorithm.</span> <ref spec=PRELOAD></p>

<p>There is no default type for resources given by the <code data-x="rel-preload">preload</code>
keyword.</p>
Expand Down Expand Up @@ -117601,8 +117626,8 @@ interface <dfn>External</dfn> {
<tr>
<th> <code data-x="">as</code>
<td> <code data-x="attr-link-as">link</code>
<td> Destination for a preload request (for <code data-x="attr-link-rel">rel</code>="<code data-x="rel-preload">preload</code>")
<td> <span data-x="concept-request-destination">Destination keyword</span>
<td> <span data-x="concept-potential-destination">Potential destination</span> for a preload request (for <code data-x="attr-link-rel">rel</code>="<code data-x="rel-preload">preload</code>")
<td> <span data-x="concept-potential-destination">Potential destination</span>
<tr>
<th> <code data-x="">async</code>
<td> <code data-x="attr-script-async">script</code>
Expand Down

0 comments on commit eb5d1cc

Please sign in to comment.