Course contentsShow
← Web Development
Lesson 1971 of 2,98236. Performance Optimization TechniquesFree lesson

When to Use Each Hint Type

Choose the right resource hint for each scenario based on timing needs, importance, and page context.

When to Use Each Hint Type

You'll learn how to pick the right resource hint for different performance scenarios so resources arrive exactly when needed — not too early, not too late.

The Core Idea

Each resource hint serves a specific timing and priority need. Think of them as different shipping speeds: dns-prefetch is like pre-addressing an envelope, preconnect is booking the courier, prefetch is sending something you'll need tomorrow, and preload is express delivery for today.

dns-prefetch: Third-Party Domains You Might Use

Use when you'll probably connect to a domain but aren't certain, or when the connection isn't immediately critical:

<!-- Analytics, social widgets, ads -->
<link rel="dns-prefetch" href="//www.google-analytics.com">

When: Lightweight optimization for domains used later in page load or conditionally.

preconnect: Domains You'll Definitely Use Soon

Use when you know you'll need resources from a domain in the current page load:

<!-- Critical font or API domain -->
<link rel="preconnect" href="https://fonts.googleapis.com">

When: Critical third-party resources loaded early (fonts, CDN assets, APIs). Limit to 2–3 domains — it's resource-intensive.

prefetch: Resources for Future Navigation

Use for assets needed on the next page the user will likely visit:

<!-- User hovering over "Products" link -->
<link rel="prefetch" href="/products.css">

When: Low-priority optimization for anticipated navigation. Fetched during browser idle time.

preload: Critical Current-Page Resources

Use for essential resources discovered late in HTML parsing:

<!-- Font needed immediately, CSS-referenced image -->
<link rel="preload" href="/hero.jpg" as="image">

When: Above-the-fold fonts, hero images, critical scripts. Only for resources you're certain will be used on this page.

modulepreload: ES Module Dependencies

Use for JavaScript modules you know will execute soon:

<link rel="modulepreload" href="/app.js">

When: Module-based apps where you want to preload dependency trees.

Key Takeaway: Choose dns-prefetch for maybe-needed domains, preconnect for certain third-parties, prefetch for next-page assets, preload for critical current-page resources, and modulepreload for ES modules — matching hint timing to actual resource needs prevents wasted bandwidth and maximizes performance gains.