diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/html/attributes%2Frel%2Fpreconnect.html | |
new repository
Diffstat (limited to 'devdocs/html/attributes%2Frel%2Fpreconnect.html')
| -rw-r--r-- | devdocs/html/attributes%2Frel%2Fpreconnect.html | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/devdocs/html/attributes%2Frel%2Fpreconnect.html b/devdocs/html/attributes%2Frel%2Fpreconnect.html new file mode 100644 index 00000000..2584c793 --- /dev/null +++ b/devdocs/html/attributes%2Frel%2Fpreconnect.html @@ -0,0 +1,68 @@ +<header><h1>rel=preconnect</h1></header><div class="section-content"> +<p>The <code>preconnect</code> keyword for the <a href="../../element/link#rel"><code>rel</code></a> attribute of the <a href="../../element/link"><code><link></code></a> element is a hint to browsers that the user is likely to need resources from the target resource's origin, and therefore the browser can likely improve the user experience by preemptively initiating a connection to that origin. Preconnecting speeds up future loads from a given origin by preemptively performing part or all of the handshake (DNS+TCP for HTTP, and DNS+TCP+TLS for HTTPS origins).</p> <p><code><link rel="preconnect"></code> will provide a benefit to any future cross-origin HTTP request, navigation or subresource. It has no benefit on same-origin requests because the connection is already open.</p> <p>If a page needs to make connections to many third-party domains, preconnecting them all can be counterproductive. The <code><link rel="preconnect"></code> hint is best used for only the most critical connections. For the others, just use <a href="dns-prefetch"><code><link rel="dns-prefetch"></code></a> to save time on the first step — the DNS lookup.</p> +</div> +<h2 id="examples">Examples</h2> +<div class="section-content"> +<div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="PYT4/2ue7hu0mrX90lIY7QK5OYVdsVtH/UE3L5jMOuA=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>link</span> <span class="token attr-name">rel</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>preconnect<span class="token punctuation">"</span></span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>https://example.com<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> +</pre> +</div> <p>You can also implement preconnect as an HTTP <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link">Link</a> header, for example:</p> <div class="code-example"> +<p class="example-header"><span class="language-name">http</span></p> +<pre data-signature="U963iZTksn1xospr3idfnUb+T9AbbIbtg/1wWsgVgiE=" data-language="http"><span class="token header"><span class="token header-name keyword">Link</span><span class="token punctuation">:</span> <span class="token header-value"><https://example.com>; rel="preconnect"</span></span> +</pre> +</div> +</div> +<h2 id="specifications">Specifications</h2> +<div class="_table"><table class="standard-table"> +<thead><tr><th scope="col">Specification</th></tr></thead> +<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/links.html#link-type-preconnect">HTML Standard <br><small># link-type-preconnect</small></a></td></tr></tbody> +</table></div> +<h2 id="browser_compatibility">Browser compatibility</h2> +<div class="_table"><table> +<thead> +<tr id="bct-browser-type"> +<th></th> +<th colspan="6">Desktop</th> +<th colspan="6">Mobile</th> +</tr> +<tr id="bct-browsers"> +<th></th> +<th>Chrome</th> +<th>Edge</th> +<th>Firefox</th> +<th>Internet Explorer</th> +<th>Opera</th> +<th>Safari</th> +<th>WebView Android</th> +<th>Chrome Android</th> +<th>Firefox for Android</th> +<th>Opera Android</th> +<th>Safari on IOS</th> +<th>Samsung Internet</th> +</tr> +</thead> +<tbody><tr> +<th><code>preconnect</code></th> +<td class="bc-supports-yes">46</td> +<td class="bc-supports-yes">79</td> +<td class="bc-supports-yes"><details><summary>39</summary>Before Firefox 41, it doesn't obey the <code>crossorigin</code> attribute.</details></td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">33</td> +<td class="bc-supports-yes">11.1</td> +<td class="bc-supports-yes">46</td> +<td class="bc-supports-yes">46</td> +<td class="bc-supports-yes"><details><summary>39</summary>Before Firefox 41, it doesn't obey the <code>crossorigin</code> attribute.</details></td> +<td class="bc-supports-yes">33</td> +<td class="bc-supports-yes">11.3</td> +<td class="bc-supports-yes">4.0</td> +</tr></tbody> +</table></div> +<h2 id="see_also">See also</h2> +<div class="section-content"><ul> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Speculative_loading">Speculative loading</a> for a comparison of <code><link rel="preconnect"></code> and other similar performance improvement features.</li> </ul></div><div class="_attribution"> + <p class="_attribution-p"> + © 2005–2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br> + <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preconnect" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preconnect</a> + </p> +</div> |
