--- url: "https://web.dev/learn/performance/resource-hints" titulek: "Assist the browser with resource hints | web.dev" h1: "Assist the browser with resource hints Stay organized with collections Save and categorize content based on your preferences." popis: "Resource hints are a collection of features available in HTML that can assist the browser in loading resources earlier and possibly even with higher resource priority. In this module, a few resource hints that can help your pages load even faster are covered." jazyk: "en" kanonicka: "https://web.dev/learn/performance/resource-hints" drobecky: ["web.dev", "Resources", "Performance"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 22:27:13" znaku: 10681 slov: 1521 kodovani: "iso-8859-2" sha256: "9c18a7b8a09b120d69760585be15f664b5b69bea542bbf65de62e8ddfdf99430" --- Assist the browser with resource hints Stay organized with collections Save and categorize content based on your preferences. In the last module about [optimizing resource loading](/learn/performance/optimize-resource-loading), you learned how various page resources such as CSS and JavaScript can affect page load speed, and how you can optimize them and their delivery to speed up the rendering of a page. This is the perfect time to move into a more advanced aspect of resource loading, and that involves helping the browser to load them faster by using resource hints. Resource hints can help developers further optimize page load time by informing the browser how to load and prioritize resources. An initial set of resource hints such as `preconnect` and `dns-prefetch` were the first to be introduced. Over time, however, `preload`, and the Fetch Priority API have followed to provide additional capabilities. Resource hints instruct the browser to perform certain actions ahead of time that could improve loading performance. Resource hints can perform actions such as performing early DNS lookups, connecting to servers ahead of time, and even fetching resources before the browser would ordinarily discover them. Resource hints may be specified in HTMLâmost often early on in the `
` elementâor [set as an HTTP header](https://almanac.httparchive.org/en/2021/resource-hints#http-header). For the scope of this module, [`preconnect`](https://www.w3.org/TR/resource-hints/#dfn-preconnect), [`dns-prefetch`](https://developer.mozilla.org/docs/Web/Performance/dns-prefetch), and [`preload`](https://developer.mozilla.org/docs/Web/HTML/Link_types/preload) are covered, as well as the speculative fetching behaviors that [`prefetch`](https://developer.mozilla.org/docs/Web/HTML/Attributes/rel/prefetch) provides. `preconnect` The `preconnect` hint is used to establish a connection to another origin from where you are fetching critical resources. For example, you may be hosting your images or assets on a CDN or other cross-origin: `` By using `preconnect`, you anticipate that the browser plans to connect to a specific cross-origin server in the *very near future*, and that the browser should open that connection as soon as possible, ideally before waiting for the HTML parser or preload scanner to do so. If you have a large amount of cross-origin resources on a page, use `preconnect` for those resources which are the most critical to the current page. A visualization of connection timings as seen in the network panel of Chrome DevTools. The timings within the red box are those involved in setting up a connection with a cross-origin server, which `preconnect` can alleviate by establishing connections sooner, rather than at the time of discovery of the cross-origin resource. A [common use case for `preconnect` is Google Fonts](https://almanac.httparchive.org/en/2021/resource-hints#fig-14). Google Fonts recommends that you `preconnect` to the `https://fonts.googleapis.com` domain that serves the `@font-face` declarations and to the `https://fonts.gstatic.com` domain that serves the font files. ` ` The `crossorigin` attribute is used to indicate whether a resource must be fetched using [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/docs/Web/HTTP/CORS). When using the `preconnect` hint, if the resource being downloaded from the origin uses CORSâsuch as font filesâthen you need to add the `crossorigin` attribute to the `preconnect` hint. `dns-prefetch` While opening connections to cross-origin servers early can significantly improve initial page load time, it may not be either reasonable or possible to establish connections to many cross-origin servers at once. If you're concerned that you may be overusing `preconnect`, a much less costly resource hint is the `dns-prefetch` hint. Per its name, `dns-prefetch` doesn't establish a *connection* to a cross-origin server, but rather just performs the [DNS lookup](https://en.wikipedia.org/wiki/Domain_Name_System#Address_resolution_mechanism) for it ahead of time. A *DNS lookup* occurs when a domain name is resolved to its underlying IP address. While layers of DNS caches at the device and network levels help to make this a generally fast process, it still takes some amount of time. ` ` DNS lookups are fairly inexpensive, and because of their relatively small cost, they may be a more appropriate tool in some cases than a `preconnect`. In particular, it may be a desirable resource hint to use in cases of links that navigate to other websites that you think the user is likely to follow. [dnstradamus](https://github.com/malchata/dnstradamus) is one such tool that does this automatically using JavaScript, and uses the [Intersection Observer API](https://developer.mozilla.org/docs/Web/API/Intersection_Observer_API) to inject `dns-prefetch` hints into the current page's HTML when links to other websites are scrolled into the user's viewport. `preload` The `preload` directive is used to initiate an early request for a resource required for rendering the page: `` `preload` directives should be limited to late-discovered critical resources. The most common use cases are font files, CSS files fetched through `@import` declarations, or CSS `background-image` resources that are likely to be [Largest Contentful Paint (LCP) candidates](/articles/lcp#what-elements-are-considered) or other LCP resources that are not discoverable in the initial HTML (for example, if loaded by JavaScript). In such cases, these files wouldn't be discovered by the preload scanner as the resource is referenced in external resources. Similarly to `preconnect`, the `preload` directive requires the `crossorigin` attribute if you are preloading a CORS resourceâsuch as fonts. If you don't add the `crossorigin` attributeâor add it for non-CORS requestsâthen the resource is downloaded by the browser *twice*, wasting bandwidth that could have been better spent on other resources. `` In the preceding HTML snippet, the browser is instructed to preload `/font.woff2` using a CORS requestâeven if `/font.woff2` is on the same domain. `prefetch` The `prefetch` directive is used to initiate a low priority request for a resource likely to be used for future navigations: `` This directive largely follows the same format as the `preload` directive, only the `` element's `rel` attribute uses a value of `"prefetch"` instead. Unlike the `preload` directive, however, `prefetch` is largely speculative in that you're initiating a fetch for a resource for a future navigation that may or may not happen. There are times when `prefetch` can be beneficialâfor example, if you've identified a user flow on your website that most users follow to completion, a `prefetch` for a render-critical resource for those future pages can help to reduce load times for them. Fetch Priority API You can use the [`Fetch Priority API`](/articles/fetch-priority) through its `fetchpriority` attribute to increase the priority of a resource. You can use the attribute with ``, `