From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/html/attributes%2Frel%2Fprefetch.html | 81 +++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 devdocs/html/attributes%2Frel%2Fprefetch.html (limited to 'devdocs/html/attributes%2Frel%2Fprefetch.html') diff --git a/devdocs/html/attributes%2Frel%2Fprefetch.html b/devdocs/html/attributes%2Frel%2Fprefetch.html new file mode 100644 index 00000000..83f845ca --- /dev/null +++ b/devdocs/html/attributes%2Frel%2Fprefetch.html @@ -0,0 +1,81 @@ +

rel=prefetch

+

The prefetch keyword for the rel attribute of the <link> element provides a hint to browsers that the user is likely to need the target resource for future navigations, and therefore the browser can likely improve the user experience by preemptively fetching and caching the resource. <link rel="prefetch"> is used for same-site navigation resources, or for subresources used by same-site pages.

The result is kept in the HTTP cache on disk. Because of this it is useful for prefetching subresources, even if they are not used by the current page. You could also use it to prefetch the next document the user will likely visit on the site. However, as a result you need to be careful with headers — for example certain Cache-Control headers could block prefetching (for example no-cache or no-store).

Note: Because of such limitations, you are advised to use the Speculation Rules API for document prefetches instead, where it is supported.

<link rel="prefetch"> is functionally equivalent to a fetch() call with a priority: "low" option set on it, except that the former will generally have an even lower priority, and it will have a Sec-Purpose: prefetch header set on the request. Note that in general browsers will give prefetch resources a lower priority than preload ones (e.g. requested via <link rel="preload">) — the current page is more important than the next.

The fetch request for a prefetch operation results in an HTTP request that includes the HTTP header Sec-Purpose: prefetch. A server might use this header to change the cache timeouts for the resources, or perform other special handling. The request will also include the Sec-Fetch-Dest header with the value set to empty.

The Accept header in the request will match the value used for normal navigation requests. This allows the browser to find the matching cached resources following navigation.

+
+

Examples

+ +

Basic prefetch

+
+

js

+
<link rel="prefetch" href="main.js" />
+
+
+ +
+

Prefetching can be used to fetch both HTML and sub-resources for a possible next navigation. A common use case is to have a simple website landing page that fetches more "heavy-weight" resources used by the rest of the site.

+

html

+
<link rel="prefetch" href="/app/style.css" />
+<link rel="prefetch" href="/landing-page" />
+
+
+
+

The effects of cache partitioning

+
+

Many browsers now implement some form of cache partitioning, which makes <link rel="prefetch"> useless for resources intended for use by different top-level sites. This includes the main document when navigating cross-site. So, for example, the following prefetch:

+

html

+
<link rel="prefetch" href="https://news.example/article" />
+
+

Would not be accessible from https://aggregator.example/.

+
+

Specifications

+
+ + +
Specification
HTML Standard
# link-type-prefetch
+

Browser compatibility

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariWebView AndroidChrome AndroidFirefox for AndroidOpera AndroidSafari on IOSSamsung Internet
prefetch
8Requires secure context
12Requires secure context
2Requires secure context
11
15Requires secure context
13.1
4.4Requires secure context
18Requires secure context
4Requires secure context
14Requires secure context
13.4
1.5Requires secure context
+

See also

+
+

+ © 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
+ https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/prefetch +

+
-- cgit v1.2.3