Course contentsShow
← Web Development
Lesson 88 of 2,9822. HTML FundamentalsFree lesson

Preloading and Resource Hints

Using rel='preload', rel='prefetch', and rel='dns-prefetch' to optimize loading.

Preloading and Resource Hints

You'll learn how to give the browser advanced hints about what resources to load, speeding up your page.

What Are Resource Hints?

Think of resource hints like telling a restaurant kitchen what you'll order before you arrive—they can start preparing, so you get your food faster. Resource hints let you tell the browser which files are important and should be loaded early or prepared in advance.

The Three Main Hint Types

rel="preload"

This tells the browser: "You'll definitely need this file soon—start downloading it now!" It's for critical resources needed on the current page.

<link rel="preload" href="critical-font.woff2" as="font" crossorigin>
<link rel="preload" href="hero-image.jpg" as="image">

The as attribute tells the browser what type of resource it is, so it can prioritize correctly.

rel="prefetch"

This is gentler: "You might need this on the next page the user visits." The browser downloads it when idle.

<link rel="prefetch" href="next-page-styles.css">

rel="dns-prefetch"

This resolves the domain name early (remember DNS from earlier lessons?), so when the browser actually needs resources from that domain, it's already looked up the IP address.

<link rel="dns-prefetch" href="https://fonts.googleapis.com">

When to Use Each

  • Preload: Critical fonts, hero images, or above-the-fold CSS
  • Prefetch: Resources for likely next pages (like search results or product details)
  • DNS-prefetch: Third-party domains you'll definitely access (analytics, fonts, APIs)

Key Takeaway: Resource hints optimize loading by letting the browser start work early—use preload for current-page essentials, prefetch for likely next-page needs, and dns-prefetch to speed up external domain connections.