Shave seconds by choosing the right hint at the right time—then prove it with before/after traces.
If you’ve ever wondered whether preload, prefetch, preconnect, or dns-prefetch will actually improve your page speed, this guide is for you. We’ll map each hint to the real problems it solves, show production‑ready patterns, and demonstrate before/after traces so you can ship changes with confidence. The emphasis is on practical wins: using preload to pull a Largest Contentful Paint (LCP) image forward, using prefetch to make the next page feel instant, using preconnect to remove handshake latency, and leaning on dns-prefetch when a light‑touch nudge is enough.
Why this works: Hints help the browser’s preloader make better decisions. When used intentionally, preload, prefetch, preconnect, and dns-prefetch reduce critical‑path delays and translate into faster LCP and quicker perceived navigations.
Trusted resources:
Table of Contents
TL;DR — when to use preload vs prefetch vs preconnect vs dns-prefetch
- Use preload to fetch a current‑page, render‑blocking or LCP‑critical asset now (hero image, web font, critical CSS/JS). Always set a correct
as
(+type
andcrossorigin
when needed). - Use prefetch to fetch a likely next‑page resource _in the background** so the next navigation is fast (document, route JS, API payload, above‑the‑fold image for the next view).
- Use preconnect to warm up DNS/TCP/TLS for origins you will definitely hit soon (fonts, CDN, analytics). This moves connection setup off the critical path.
- Use dns-prefetch to resolve DNS only for possible third‑party origins when you can’t justify a full preconnect.
Proof process: capture controlled before/after runs (same throttling, cache mode, device). Report deltas in LCP, TTFB, Start Render and connection timings. If preload doesn’t move LCP or prefetch doesn’t improve next‑page timings, roll back.
Trusted resources:
How resource hints work: priorities, the preloader, and the network (DNS → TCP → TLS)
The browser’s preloader and scheduler don’t always discover your critical assets soon enough. preload
and prefetch
create explicit fetches; preconnect
and dns-prefetch
warm up connection steps so subsequent requests start faster. The key is to align each hint with how the network actually behaves.
Priorities and the as
attribute
rel="preload"
and rel="prefetch"
respect the as
destination (image, script, style, font). A wrong as
can down‑prioritize a preload
(or worse, cause a duplicate fetch) while a correct as
lets the browser put the preload
on the right queue. Fonts and images may also need type
and crossorigin
for cache/connection reuse.
Cache semantics and reuse
A prefetch
typically lands in the HTTP cache and can be reused on the next navigation if headers allow. Eviction is possible—another reason to prefer smaller, high‑hit‑rate prefetches. A preload
is for this page; it should match the eventual request URL exactly to avoid a double download.
Connection setup
preconnect
is a head start: DNS lookup, TCP handshake, and (for HTTPS) TLS. That trims 100–500 ms off the first request to that origin. When usage is uncertain or you only want to cheapen the first lookup, dns-prefetch
performs DNS resolution alone.
Trusted resources:
Preload: make current‑page critical assets arrive sooner
When the bottleneck is discovery—not bandwidth—preload
is your scalpel. Use it to fetch the LCP image, critical CSS, essential module, or a cross‑origin font early enough to matter. Done right, a preload
aligns resource priority with your intent and removes “late discovery” from the waterfall.
When to use preload
- The asset is required on this page and drives render speed (LCP hero, above‑the‑fold CSS, essential script).
- The browser would otherwise discover it late (e.g., CSS‑discovered fonts, JS‑injected images).
- You can specify a correct
as
and, if cross‑origin applies, a matchingtype
andcrossorigin
so thepreload
ed resource is reusable.
Preload code patterns
<!-- LCP hero image with srcset (avoid wrong variant) -->
<link rel="preload"
as="image"
href="/images/hero.avif"
imagesrcset="/images/hero-640.avif 640w, /images/hero-1280.avif 1280w"
imagesizes="(min-width: 980px) 1280px, 100vw">
<!-- Critical CSS: fetch early, apply onload -->
<link rel="preload" as="style" href="/css/critical.css" onload="this.rel='stylesheet'">
<!-- Web font: early fetch + CORS for reuse -->
<link rel="preload" as="font" type="font/woff2" href="/fonts/inter-var.woff2" crossorigin>
Guardrails for reliable preload
- Match URLs exactly. A mismatched query string causes a duplicate request, negating the
preload
. - Match
as
andtype
. If the runtime request differs, yourpreload
may not be reused. - Pair with
fetchpriority
where appropriate. For truly time‑sensitive images, setfetchpriority="high"
on the<img>
and keep thepreload
.
Trusted resources:
Prefetch: speed up likely next navigations
When you can predict where users are headed next, prefetch
pays off. It fetches documents or subresources in the background, so the subsequent navigation can reuse what’s already warm. Use prefetch
judiciously: aim for high hit‑rate, small payloads, and idle‑time scheduling.
When to use prefetch
- You have high‑confidence next steps (checkout from cart, “next article”, popular category).
- You’re loading route JS, critical CSS, or hero images for the next screen.
- You can throttle
prefetch
by network conditions and user signals to avoid waste.
Prefetch code patterns
<!-- Prefetch a likely next page -->
<link rel="prefetch" href="/pricing" as="document">
<!-- Prefetch a route’s JS chunk for an SPA/MPA -->
<link rel="prefetch" href="/static/js/route-pricing.js" as="script">
Prefetch hygiene
- Gate on connection quality. Honor
Save-Data
, Effective Connection Type, or your own heuristics. - Measure hit‑rate. If a
prefetch
is rarely used, remove it. - Keep it same‑site where possible for better cache reuse; cross‑origin document prefetches are often constrained by headers.
Trusted resources:
Preconnect: warm up origins you will definitely use
A big chunk of “nothing happening” in a waterfall is often connection setup. preconnect
moves DNS, TCP, and TLS earlier so the first request to that origin starts transferring bytes sooner. Reserve preconnect
for must‑hit origins: fonts, image CDN, analytics, auth, or API endpoints you know this page will call.
When to use preconnect
- The origin is guaranteed to be used (e.g.,
fonts.gstatic.com
, your image CDN, analytics collector). - The initial request to that origin is on the critical path (fonts for first paint, hero image, critical API).
Preconnect code patterns
<!-- Google Fonts: two origins, font origin needs crossorigin -->
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preconnect" href="https://fonts.googleapis.com">
<!-- Image CDN -->
<link rel="preconnect" href="https://cdn.example.com">
Preconnect hygiene
- Limit the set. Each
preconnect
ties up sockets and device power; pick 2–3 critical origins. - Add
crossorigin
when required. Fonts are fetched with CORS; without it, the connection/cache may not be reused.
Trusted resources:
- Preconnect to required origins (Chrome Docs)
- Establish connections early: preconnect & dns-prefetch (web.dev)
dns-prefetch: cheap DNS lookups for possible third‑party origins
Sometimes you’re unsure whether a third‑party origin will be needed on this page. dns-prefetch
is the lightweight nudge: it resolves the hostname now so that, if requested later, the first request avoids a DNS stall. It’s lower impact than preconnect
and useful for uncertain analytics, ads, embeds, or social widgets.
dns-prefetch in practice
<link rel="dns-prefetch" href="//cdn.example.net">
Control the default behavior with the response header X-DNS-Prefetch-Control: on|off
.
When to prefer dns-prefetch over preconnect
- Usage is conditional or low‑confidence.
- You have many potential third‑party hosts and don’t want to saturate sockets.
- You want the benefit of early DNS without the heavier cost of
preconnect
.
Trusted resources:
Decision tree: preload vs prefetch vs preconnect vs dns-prefetch
Use this quick flow to pick the right tool:
- Is the resource needed on the current page? →
preload
with the rightas
(andtype
/crossorigin
if needed). - Is it for a likely next page? →
prefetch
during idle, network‑aware. - Is connection setup to another origin the bottleneck? →
preconnect
(addcrossorigin
when appropriate). - Is usage uncertain and DNS alone helps? →
dns-prefetch
.
Edge cases
modulepreload
for ESM graphs whenpreload
asscript
won’t wire dependencies.- Fonts: often
preconnect
tofonts.gstatic.com
andpreload
the font file with the correctas
andtype
. - Responsive images: pair
preload
withimagesrcset
/imagesizes
to avoid fetching the wrong variant.
Trusted resources:
Pitfalls to avoid: wrong as
, double downloads, over‑prefetch, and over‑preconnect
- Wrong
as
on preload. Mismatchedas
/type
leads to mis‑prioritization and duplicate fetching. Always alignpreload
with the eventual request’s destination and MIME. - Missing
crossorigin
. Cross‑origin fonts and sometimes images require it for connection/cache reuse—without it, yourpreload
may not help. - Over‑prefetch. On cellular or low‑end devices, aggressive
prefetch
wastes bandwidth and battery. Use network‑aware guards and idle‑time scheduling. - Over‑preconnect. Spraying
preconnect
hints at many hosts creates socket pressure and can slow the page down. - Preloading non‑critical assets. A misplaced
preload
can invert priorities and delay LCP.
Trusted resources:
- dns-prefetch & preconnect: 7 tips, tricks, pitfalls (Expedia Group Tech)
- Speed up next-page navigations with prefetching (Addy Osmani)
Implementation patterns: HTML tags, HTTP Link:
headers, and CMS/frameworks
Inline HTML in <head>
<link rel="preload" as="script" href="/js/app-critical.js">
<link rel="prefetch" as="document" href="/next">
<link rel="preconnect" href="https://img.cdn.example" crossorigin>
<link rel="dns-prefetch" href="//ads.example.net">
HTTP Link:
headers (server‑side)
Link: </images/hero.avif>; rel=preload; as=image
Link: <https://cdn.example.com>; rel=preconnect
Nginx:
add_header Link "</images/hero.avif>; rel=preload; as=image" always;
add_header Link "<https://cdn.example.com>; rel=preconnect" always;
Apache:
Header add Link "</images/hero.avif>; rel=preload; as=image"
Header add Link "<https://cdn.example.com>; rel=preconnect"
WordPress/CMS integration
Use the wp_resource_hints
filter to register preconnect
/dns-prefetch
. Print explicit preload
tags for critical assets discovered late.
add_filter('wp_resource_hints', function($urls, $relation_type){
if ($relation_type === 'preconnect') {
$urls[] = 'https://fonts.gstatic.com';
}
if ($relation_type === 'dns-prefetch') {
$urls[] = '//cdn.example.net';
}
return $urls;
}, 10, 2);
Trusted resources:
Measurement plan: capture before/after traces and report wins
To claim success you need reproducible data. Here’s a minimal lab protocol:
- Pick a stable page and record a baseline with WebPageTest and Chrome DevTools (mobile throttling, cache disabled for cold loads). Keep settings identical between runs.
- Add a single change: e.g.,
preconnect
to your image CDN orpreload
the LCP image or web font. - Re‑run the same tests. Export waterfalls and note LCP, TTFB, Start Render, and connection setup time.
- Compare deltas. If the
preload
didn’t shift LCP earlier, or aprefetch
didn’t reduce next‑page latency, revert and try a different target.
What to look for in DevTools
- For
preload
: theInitiator
column showslink preload
, and the request begins earlier in the timeline. - For
preconnect
: DNS/TCP/TLS blocks shift left of the first request to that origin. - For
prefetch
: the prefetched file appears with low priority, then is reused on navigation.
Trusted resources:
Real‑world case studies with before/after traces
- Google Fonts — preconnect: Adding
preconnect
tofonts.gstatic.com
withcrossorigin
reduces font start latency; CDN Planet documents setup and waterfalls. This is a classic example wherepreconnect
pluspreload
of the font file improves first paint and LCP. - Akamai data — preconnect behavior: Platform‑scale experiments examine how browsers establish connections from
preconnect
hints, providing insight into when the hint translates into measurable wins.
When you adapt these to your stack, keep origin counts tight and focus on LCP‑critical requests—often a preload
for the LCP image plus a preconnect
to the font or image origin.
Trusted resources:
Launch checklist: safe preload/prefetch/preconnect/dns-prefetch
preload
uses correctas
+type
; thepreload
URL exactly matches the runtime request;crossorigin
for fonts/cross‑origin images.prefetch
only when next‑page likelihood is high; schedule during idle; throttle on slow connections; measure hit‑rate and remove low‑yield entries.preconnect
only for must‑hit origins; cap to 2–3; addcrossorigin
for fonts; confirm it shortens the first byte to that origin.dns-prefetch
for low‑confidence third‑party hosts where DNS latency matters.- Always attach before/after traces to PRs. If LCP/next‑page gains aren’t there, roll back.
Trusted resources:
- Optimize resource loading with the Fetch Priority API (web.dev)
- Resource hints: Preload, Prefetch, Preconnect (KeyCDN)
FAQ & gotchas about preload, prefetch, preconnect, dns-prefetch
Should I use modulepreload
or preload as="script"
for ESM?
Use modulepreload
to fetch and prepare module graphs so dependencies are ready; plain preload
as script
won’t wire the graph.
Why didn’t my preload help LCP?
Common culprits: wrong as
/type
, the LCP element changes per viewport, or the preload
URL doesn’t match the runtime request. Verify in DevTools and ensure the <img>
also advertises the right candidate (consider fetchpriority
for critical images).
Is preconnect always better than dns-prefetch?
No. preconnect
is heavier and should be reserved for origins you’ll definitely hit soon; dns-prefetch
is cheaper for uncertain third‑party hosts.
Does prefetch waste data?
It can. Limit prefetch
to high‑confidence predictions and apply network‑aware gating.
How do Link headers interact with HTML tags?
They share semantics; use server‑side Link:
when you need hints before HTML parses, and HTML tags for page‑specific overrides.
Trusted resources:
References & further reading
Specs and primers that underpin the recommendations in this article:
- W3C Resource Hints — definitions for
dns-prefetch
,preconnect
,prefetch
, and prerender. - W3C Preload — authoritative definition of
preload
andLink
semantics. - WHATWG HTML — living standard with link types for
preload
,prefetch
,preconnect
,dns-prefetch
, and modulepreload. - Vendor guidance — Lighthouse audits for
preconnect
, LCP explainers, and implementation guides forpreload
,prefetch
, anddns-prefetch
.
Trusted resources: