Skip to content

Commit db17411

Browse files
committed
Add explanation and examples for early hints
1 parent 77c3373 commit db17411

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

source

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14341,21 +14341,68 @@ interface <dfn interface>HTMLLinkElement</dfn> : <span>HTMLElement</span> {
1434114341
<li><p>Return <var>links</var>.</p></li>
1434214342
</ol>
1434314343

14344-
<h6>Early Hint Headers</h6>
14344+
<h6>Early Hints</h6>
1434514345

14346-
<p>Early hint headers allow user-agents to perform some operations, such as speculative loading
14347-
resources that are likely to be used by the document, before the navigation request is fully
14346+
<p><dfn>Early hints</dfn> allow user-agents to perform some operations, such as to speculatively
14347+
load resources that are likely to be used by the document, before the navigation request is fully
1434814348
handled by the server and a response code is served. Servers can indicate early hints by serving a
1434914349
<span data-x="concept-response">response</span> with a 103 status code before serving the final
1435014350
<span data-x="concept-response">response</span>.<ref spec=RFC8297></p>
1435114351

14352+
<div class="example">
14353+
<p>For example, given the following sequence of responses:</p>
14354+
<pre>
14355+
103 Early Hint
14356+
Link: &lt;/image.png&gt;; rel=preload; as=image
14357+
</pre>
14358+
14359+
<pre>
14360+
200 OK
14361+
Content-Type: text/html
14362+
14363+
&lt;!DOCTYPE html&gt;
14364+
...
14365+
&lt;img src="/image.png"&gt;
14366+
</pre>
14367+
14368+
<p>the image will start loading before the HTML content arrives.</p>
14369+
</div>
14370+
1435214371
<p class="note">Only the first early hint response served during the navigation is handled, and it
14353-
is discarded if it is succeeded by a cross-origin redirect. In addition to the early hint, the 103
14354-
response may also contain a <span>Content Security Policy</span> header, which is enforced when
14355-
processing the early hints.</p>
14372+
is discarded if it is succeeded by a cross-origin redirect. In addition to the early hint, it is
14373+
possbile that the 103 response contains a <span>Content Security Policy</span> header, which is
14374+
enforced when processing the early hints.</p>
14375+
14376+
<div class="example">
14377+
<p>For example, given the following sequence of responses:</p>
14378+
<pre>
14379+
103 Early Hint
14380+
Content-Security-Policy: style-src: self;
14381+
Link: &lt;/style.css&gt;; rel=preload; as=style
14382+
</pre>
14383+
14384+
<pre>
14385+
103 Early Hint
14386+
Link: &lt;/image.png&gt;; rel=preload; as=image
14387+
</pre>
14388+
14389+
<pre>
14390+
302 Redirect
14391+
Location: /alternate.html
14392+
</pre>
14393+
14394+
<pre>
14395+
200 OK
14396+
Content-Security-Policy: style-src: none;
14397+
Link: &lt;/font.ttf&gt;; rel=prelad; as=font
14398+
</pre>
14399+
14400+
<p>The font and style would be loaded, and the image will be discarded, as only the first early hint
14401+
response in the final redirect chain is respected. The late <span>Content Security Policy</span>
14402+
header comes after the request to fetch the style has already been performed, but the style will
14403+
not be accessible to the document.</p>
14404+
</div>
1435614405

14357-
<p class="example">
14358-
</p>
1435914406

1436014407
<p>To <dfn>process early hint headers</dfn> given a
1436114408
<span data-x="concept-response">response</span> <var>response</var> and an
@@ -88787,7 +88834,7 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
8878788834
<li>
8878888835
<p>Set <var>uncommittedPreloads</var> to null.</p>
8878988836

88790-
<p class="note">Preloaded links from <span data-x="process early hint headers">early hint
88837+
<p class="note">Preloaded links from <span data-x="early hints">early hint
8879188838
headers</span> remain in the preload cache after a <span>same origin</span> redirect, but
8879288839
get discarded when the redirect is cross-origin.</p>
8879388840
</li>
@@ -127445,6 +127492,9 @@ INSERT INTERFACES HERE
127445127492
<dt id="refsRFC7578">[RFC7578]</dt>
127446127493
<dd><cite><a href="https://tools.ietf.org/html/rfc7578">Returning Values from Forms: multipart/form-data</a></cite>, L. Masinter. IETF.</dd>
127447127494

127495+
<dt id="refsRFC8297">[RFC8297]</dt>
127496+
<dd><cite><a href="https://tools.ietf.org/html/rfc8297">An HTTP Status Code for Indicating Hints</a></cite>, K. Oku. IETF.</dd>
127497+
127448127498
<dt id="refsSCREENORIENTATION">[SCREENORIENTATION]</dt>
127449127499
<dd><cite><a href="https://w3c.github.io/screen-orientation/">Screen Orientation API</a></cite>, M. Lamouri, M. Cáceres. W3C.</dd>
127450127500

0 commit comments

Comments
 (0)