Lesson 38 of 55 · HTML
Performance – Preload, Prefetch, and Preconnect
Duration: 10 min
Resource Hints
Guide the browser to fetch critical assets earlier.
<!-- Preload critical CSS -->
<link rel='preload' href='styles/main.css' as='style' onload='this.rel="stylesheet"'>
<!-- Prefetch a page the user might visit next -->
<link rel='prefetch' href='/about.html'>
<!-- Preconnect to third‑party CDN -->
<link rel='preconnect' href='https://fonts.gstatic.com' crossorigin>
How they work
preload– Loads the resource immediately and makes it available for use as soon as it’s needed; must specify theasattribute (script,style,font,image).prefetch– Low‑priority fetch for resources likely needed later (e.g., next article).preconnect– Opens early DNS resolution, TLS handshake, and TCP connection to an external origin.
Performance tips
- Use
preloadsparingly; over‑preloading can block other critical requests. - Pair
preloadwithas='font'andcrossoriginfor web fonts. - Use
prefetchfor resources the user is highly likely to navigate to next. - Keep the number of
preconnectlinks low – each initiates a network round‑trip.
Quick checklist for resource hints
- Critical CSS preloaded with correct
as='style'? ✅ - Future navigation assets prefetched (
rel='prefetch')? ✅ - External origins preconnected (
rel='preconnect')? ✅ crossoriginset on fonts and other cross‑origin resources? ✅- No unnecessary preloads that block rendering? ✅
Tip: Verify that your hints are respected using Chrome’s Network panel or the Coverage tool.