HTML Resource Hints: Preload, Preconnect and Prefetch
Preload a current-page resource
Preload identifies a resource likely needed for the current navigation, with as describing its destination. It fetches a resource but does not apply a stylesheet or execute a script by itself. The example path is illustrative; actual network access is disabled during validation.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Metadata practice</title> <link rel="preload" href="/styles.css" as="style"> <link rel="stylesheet" href="/styles.css"> </head> <body> <h1>Course</h1> </body></html>The preload and stylesheet point to the same path. Actual reuse is not measured.
Prepare a connection
preconnect suggests early setup of a connection to an origin; dns-prefetch suggests resolving a hostname. Neither fetches the actual resource body. Avoid opening many unused connections.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Metadata practice</title> <link rel="preconnect" href="https://assets.example.com" crossorigin> <link rel="dns-prefetch" href="https://images.example.com"> </head> <body> <h1>Resource hints</h1> </body></html>The two distinct hints are declared; connections are not measured.
Prepare possible future navigation
Prefetch suggests fetching a resource that might be useful later, unlike preload for current needs. Browsers may ignore or defer hints. For fonts, preload as="font" with a matching CORS mode (commonly crossorigin) helps avoid a mismatched request.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Metadata practice</title> <link rel="prefetch" href="/next.html"> <link rel="preload" href="/font.woff2" as="font" type="font/woff2" crossorigin> </head> <body> <h1>Next lesson</h1> </body></html>The future-page hint and current font hint have different relationships.
Common mistakes and practice
Use performance measurements before and after adding hints. Match URL, destination and credentials mode; excessive preloads can compete for bandwidth. modulepreload is a separate hint for module scripts, covered later.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Resource Hints: Preload, Preconnect and Prefetch — Knowledge Check
Apply the metadata concepts taught in this lesson.
Which hint is intended for a needed current-page resource?
Does preload as=style alone apply CSS?
What does dns-prefetch prepare?
Which hint describes a possible future resource?
Why measure after adding hints?