Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Web Performance & Core Web Vitals
  1. 1.Introduction to Web Performance & Business Impact
  2. 2.Core Web Vitals & Practical Measurement Tools
  3. 3.Optimizing the Critical Rendering Path & Basic Asset Delivery
  4. 4.JavaScript Performance & Bundle Optimization
  5. 5.Image, Video, and Media Optimization Strategies
  6. 6.Network Performance: HTTP/2, Caching, and CDNs
  7. 7.Resource Hints & Advanced Loading Strategies
  8. 8.Frontend Architectures & Server-Side Rendering Performance
  9. 9.Performance Budgets, RUM, and Continuous Monitoring
  10. 10.Advanced Browser APIs & Offloading Work with Workers
Web Performance & Core Web Vitals
07

Web Fundamentals · Lesson 7 of 10 · 4 min

Resource Hints & Advanced Loading Strategies

This is how you show an interviewer you think about the network waterfall, not just the code.

By default, the browser is reactive. It parses HTML, finds a <link> to a CSS file, fetches it, parses the CSS, finds a url() for a font, and only then starts fetching the font. This discovery chain creates a request waterfall with unnecessary idle time. Resource hints let you tell the browser what it's going to need ahead of time, turning that idle time into productive download time.

Your job is to give the browser a schedule of what's important, for this page and the next.

Warm up connections with dns-prefetch and preconnect

When you fetch a resource from a new origin, the browser has to do a DNS lookup, then a TCP handshake, then a TLS negotiation. This can add hundreds of milliseconds of latency before the first byte is even requested. dns-prefetch and preconnect let you do this work in advance.

dns-prefetch is the cheapest hint. It only does the DNS lookup.

<link rel="dns-prefetch" href="https://www.google-analytics.com">

Use it for third-party domains you'll probably need, but that aren't critical. Think analytics, A/B testing scripts, or social media widgets. The cost is negligible.

preconnect does the full connection: DNS, TCP, and TLS.

<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

Use this for critical third-party origins that you know you will fetch resources from, like a font provider or your primary asset CDN. The connection will be ready and waiting.

The trap: Overusing preconnect. Each one opens and maintains a connection, which consumes server and client resources. A browser might only keep a few connections open. Stick to your most critical 1-2 third-party origins. For everything else, dns-prefetch is enough.

Interview question: "When would you use preconnect over dns-prefetch?"

Your answer: "I use preconnect for origins that are critical to the initial render path and that I know will be used immediately, like my font CDN. It saves round-trip time on the full connection setup. For less critical, third-party origins that might be used later, like an analytics provider, I use dns-prefetch. It's a lower-cost hint that just warms up the DNS."

Fix the waterfall with preload

preload is your most powerful tool. It tells the browser to fetch a resource for the current page with high priority, but without executing or applying it. This is for critical resources the browser discovers too late.

The classic example is a font file referenced inside a CSS file. The browser must download and parse the CSS before it even knows the font exists. Preloading the font decouples discovery from fetching.

<link rel="preload" href="/fonts/my-font.woff2" as="font" type="font/woff2" crossorigin>

The as attribute is mandatory. It tells the browser the resource's priority, what security policies to apply, and the correct Accept request header to send. Forgetting it makes the hint useless. For fonts, crossorigin is also required because they are fetched in an anonymous CORS mode.

Good candidates for preload:

  • Fonts defined in CSS.
  • The primary image for your Largest Contentful Paint (LCP) element, if it's a background-image in CSS.
  • The critical CSS or JavaScript file needed for the initial interactive view.

The trap: Preloading something that isn't critical. preload requests are high-priority. If you preload a non-essential asset, you might be pushing back the download of something that is essential, like your main CSS or JS bundle. Audit your waterfall chart in DevTools to find what's truly blocking and discovered late.

A complete example in your <head>

Here is how these hints work together to optimize a typical page load.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Optimized Head</title>

  <!-- 1. Preconnect to the most critical third-party origin (e.g., font CDN). -->
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

  <!-- 2. DNS-prefetch other third-party origins. -->
  <link rel="dns-prefetch" href="https://www.google-analytics.com">

  <!-- 3. Preload a critical, late-discovered font. -->
  <link rel="preload" href="/fonts/Inter-Regular.woff2" as="font" type="font/woff2" crossorigin>

  <!-- 4. Preload the LCP background image. -->
  <link rel="preload" href="/images/hero-background.webp" as="image">

  <!-- 5. Prefetch assets for a likely next navigation (e.g., the next step in a checkout flow). -->
  <link rel="prefetch" href="/js/checkout-step-2.js" as="script">

  <!-- 6. The browser can now fetch these while also fetching the main CSS. -->
  <link rel="stylesheet" href="/css/main.css">
</head>
<body>
  <!-- ... -->
</body>
</html>

How dns-prefetch and preconnect map to the connection

This diagram shows what each hint accomplishes during the connection setup process. preconnect does it all, while dns-prefetch just handles the first step.

Plan for future navigations with prefetch and prerender

While preload is for the current page, prefetch is for a future page. It tells the browser to fetch a resource with low priority when it's idle. This is for assets you are reasonably sure the user will need on their next navigation.

<link rel="prefetch" href="/next-page.html" as="document">

Good use cases: the next article in a series, the second page of a multi-page form, or the main JS bundle for a page linked from your hero CTA. It's a low-cost, low-risk optimization.

prerender is the most aggressive hint. It loads and renders an entire page in a background tab. It's extremely resource-intensive and should only be used when you have very high confidence in the user's next action, like clicking "Proceed to Checkout". The modern approach is the Speculation Rules API, which offers more control. In an interview, it's enough to know what prerender does and why it's used sparingly.

Finally, modulepreload is a specialized hint for preloading JavaScript modules (<script type="module">). It has the advantage of also fetching all the module's dependencies recursively.

Try it

Open the network tab in your browser's dev tools for a site you use often. Identify a critical font or image that is part of a long request chain. Write the full <link rel="preload"> tag you would add to the site's <head> to optimize its loading, and write one sentence explaining your choice.

Next: Now that resources are arriving faster, we need to optimize what happens on the server with Frontend Architectures & Server-Side Rendering Performance.

Lock it in — apply this lesson under interview conditions.

Try an AI mock interview
Previous

Network Performance: HTTP/2, Caching, and CDNs

Next

Frontend Architectures & Server-Side Rendering Performance