Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 37 ยท Network and Caching

Resource Hints and Priorities

Learn how browsers prioritise requests, and how preload, preconnect, dns-prefetch, prefetch, fetchpriority and 103 Early Hints help the browser fetch the right things sooner.

Browsers decide what to download first using their own heuristics. They are good at it, but they only know what they have discovered so far. Resource hints are small instructions you add to tell the browser about important resources earlier or to adjust their priority.

Hints are powerful and easy to overuse. Every hint competes for the same limited bandwidth, so the rule is: hint only what you know is critical.

How browsers prioritise

The browser assigns each request a priority (Highest, High, Medium, Low, Lowest) based on its type and position:

  • HTML and CSS in the head: highest.
  • Fonts needed by visible text, and scripts in the head: high.
  • Images in the viewport: high; images far below: low.
  • async scripts, prefetches: low.

Priorities shape the order in which bytes are sent. Lower priority requests may wait until higher ones finish.

dns-prefetch and preconnect

Before downloading from a third-party origin, the browser must do DNS, TCP and TLS. You can warm that up:

HTML
<link rel="preconnect" href="https://cdn.example.com">
<link rel="preconnect" href="https://fonts.example.net" crossorigin>
<link rel="dns-prefetch" href="https://analytics.example.org">
  • dns-prefetch resolves the hostname only. It is cheap and widely supported; use it as a lightweight fallback or for less important origins.
  • preconnect does DNS, TCP and TLS. Use it for origins you are certain to use soon. Add crossorigin when the resource will be fetched in CORS mode (fonts always are).

Limit yourself to two or three preconnects: open connections that go unused are wasted and can steal early bandwidth.

preload

preload tells the browser to fetch a resource it will need, with high priority, right now, even though it has not found it in the HTML yet.

HTML
<link rel="preload" href="/fonts/inter.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/img/hero.avif" as="image" type="image/avif">
<link rel="preload" href="/css/critical.css" as="style">

Always include as so the browser sets the right priority and cache entry. Good candidates:

  • A font referenced inside a CSS file (otherwise discovered late).
  • The LCP image when it is a CSS background or set by JavaScript.
  • A script or CSS file that is requested by another file.

A preloaded resource that is not used within a few seconds triggers a console warning. Preloading too much slows down the resources that really are needed.

For responsive images, preload the right candidate with imagesrcset and imagesizes:

HTML
<link rel="preload" as="image"
      imagesrcset="/img/hero-480.avif 480w, /img/hero-960.avif 960w"
      imagesizes="100vw">

prefetch and prerender

prefetch downloads a resource at lowest priority for a future navigation, when the browser is idle.

HTML
<link rel="prefetch" href="/checkout.js">

It suits "the user will probably go here next" cases. The Speculation Rules API goes further: it can prefetch or fully prerender the next page so it opens instantly.

HTML
<script type="speculationrules">
{ "prerender": [{ "where": { "href_matches": "/next/*" } }] }
</script>

Use prerender carefully: the page's scripts and analytics run before the user sees it.

fetchpriority

fetchpriority raises or lowers the priority of a single request with the values high, low or auto:

HTML
<img src="/img/hero.avif" fetchpriority="high" width="1200" height="600" alt="...">
<img src="/img/footer-badge.png" fetchpriority="low" loading="lazy" width="80" height="80" alt="...">
<script src="/js/chat.js" async fetchpriority="low"></script>

It also works for fetch(): fetch(url, { priority: "low" }). It is the most precise tool for fixing a late or mis-prioritised LCP image.

103 Early Hints

While the server is still preparing the HTML, it can send an interim 103 Early Hints response with Link headers for preloading and preconnecting. The browser starts work during the server's thinking time, which helps when TTFB is large.

HTTP
HTTP/2 103
Link: </css/main.css>; rel=preload; as=style
Link: <https://cdn.example.com>; rel=preconnect

Check your hints from JavaScript

Detect which hints a document declares

You could turn this into an automated check in your build or a test that warns when a page declares too many hints.

Choosing the right hint

JS Pick a hint for a scenario

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The last line is the most common outcome: most resources need no hint at all.

flowchart TD
  A["Is it needed on this page?"] -->|Yes, soon| B{"Already in the HTML?"}
  B -->|No| C["preload"]
  B -->|Yes, wrong priority| D["fetchpriority"]
  A -->|Different origin| E["preconnect"]
  A -->|Next page| F["prefetch / prerender"]

Match the hint to the situation.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which hint opens DNS, TCP and TLS to another origin early?

    preconnect sets up the full connection; dns-prefetch only resolves the hostname.
  2. 2. Why does preload need the as attribute?

    Without as, the browser cannot prioritise it properly and may fetch it twice.
  3. 3. Which attribute raises the priority of an LCP image already in the HTML?

    fetchpriority=high tells the browser the image is important.
  4. 4. What is prefetch used for?

    Prefetch fills the cache when idle so the next page can start faster.

Summary

  • Hints tell the browser about resources earlier; use them for known-critical items only.
  • preconnect warms third-party origins, preload fetches late-discovered critical files, prefetch prepares future navigations.
  • fetchpriority adjusts one request's priority, ideal for the LCP image.
  • 103 Early Hints let the server start preloads during server time.

Next: Image Formats and Sizes