How to Send Early Hints to Preload Resources
Use 103 Early Hints to start preloading critical subresources before the final response, and understand when it helps and when it does not.
On this page
Introduction
A browser cannot start fetching a page’s stylesheet or main script until it has parsed the HTML that references them. When the server needs time to compute that HTML, the client sits idle. Early Hints addresses this by allowing the server to send an interim 103 response with Link headers naming resources the client may want, long before the final response. The client can begin fetching those resources in parallel with the server finishing its work.
This tutorial implements Early Hints for a Node.js server, explains the 103 status and its Link headers, describes when the optimization actually helps, and stresses measuring the effect rather than assuming it. The examples use a template render that takes a few hundred milliseconds, which is the case where hints shine.
How 103 Early Hints works
HTTP allows interim responses before the final one. A 103 Early Hints is one or more interim responses, each carrying headers the client can act on immediately, most commonly Link headers with rel=preload or rel=preconnect. After the interim responses, the server continues processing and eventually sends the real response with its own status and body. The client renders nothing from a 103; it only learns what to fetch.
Because the hints are provisional, the client treats them as advice, not a contract. If a hinted resource is already cached, the client skips it. If the hint is wrong, the cost is a wasted fetch, not a broken page. This advisory nature is why the client decides, and why Early Hints withstood the problems that sank server push, where the server fetched resources the client might already have.
import { createServer } from 'node:http';
createServer(async (req, res) => {
// interim hints before the expensive work
res.writeEarlyHints({
link: [
'</styles/main.css>; rel=preload; as=style',
'</scripts/app.js>; rel=preload; as=script',
'<https://cdn.example.com>; rel=preconnect',
],
});
const html = await renderPage(); // slow: 200-400ms
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
res.end(html);
}).listen(3000);
Name only genuinely critical resources
Early Hints is most valuable for the render-blocking resources on the critical path: the main stylesheet, a critical font, and the entry script. Hints for resources below the fold or conditionally used waste client work and can starve the critical ones. Resist the temptation to list everything; the value comes from prioritizing a few resources that block first paint.
Match the hint to how the resource is used. A stylesheet preloaded with as=style must actually be a stylesheet; a font needs crossorigin if it is fetched cross-origin, because a font request without the right credentials mode will be duplicated. A preconnect needs only the origin and is cheap; a preload needs the full URL and the correct as value. A mismatch causes the browser to fetch the resource twice, once from the hint and once from the normal reference.
Keep hints consistent with caching
The hinted URL must be the same URL the page references, including any fingerprint or version query. If the page links to /app.abc123.js and the hint preloads /app.js, the client fetches both. Ensure the hint does not reference a resource behind a different origin or a different caching policy than the real use, or the preload is discarded when the page requests the resource with different attributes.
Hints themselves are not cached as a body; they are advisory headers. The server can vary them per route, sending different hints for a page that needs a chart library and one that does not. Keep the hints small and stable so they do not add meaningful header overhead to every response.
Measure the effect
Early Hints is not universally beneficial. It helps when the final response is slow and there are critical resources to fetch. It helps little when the response is fast, because the client would not have been idle anyway, or when the resources are already cached. Deploy it behind a measurement: compare first contentful paint or largest contentful paint with and without hints on a representative page. If the delta is not measurable, remove it rather than carry the complexity.
Watch for the case where hints hurt. If the server sends hints for resources it then does not reference, or references differently, the client fetches extra bytes it may have already cached. A hint that names a resource the client has cached is cheap to ignore, but a hint whose attributes differ from the real use causes a duplicate fetch. Measure both the win and the risk.
curl -sD - -o /dev/null http://localhost:3000/page
# you should see one or more 'HTTP/1.1 103 Early Hints' blocks before the 200
Test that hints match reality
Write a test that renders the page, captures the Link headers from the interim response, and asserts that each preloaded URL and its as attribute match a resource the final HTML actually references. This catches the drift that turns a helpful hint into a duplicate fetch. Also test that a route without critical subresources sends no hints, so the optimization stays targeted rather than blanket.
Common pitfalls
Preloading resources the page does not reference, mismatching the as attribute or omitting crossorigin for fonts, slowing a fast response with hints that help nobody, sending hints for already-cached assets on every page, and treating Early Hints as a guaranteed win instead of a measured improvement are the recurring mistakes. Matching hints to real usage and measuring the effect addresses them.
Conclusion
Early Hints lets a server hand the client a head start on critical subresources before the main response is ready. Send a 103 with Link: rel=preload for the render-blocking resources only, keep URLs and attributes identical to the page’s real references, and measure the latency change before keeping it. Self-check by asserting every hinted URL appears in the final HTML with matching attributes. Used deliberately and measured, it removes idle time on slow-rendering pages.
Sources: RFC 8297: An HTTP Status Code for Indicating Hints, MDN: 103 Early Hints, web.dev: Early Hints.
FAQ
- Does 103 replace HTTP/2 server push?
- It is the practical successor for many cases. Server push had cache and priority problems and was removed from browsers; Early Hints lets the client decide what to fetch, which respects its cache and its judgment.
- Should I always send Early Hints?
- No. It helps when the final response is slow to compute and there are critical subresources the client needs. For a fast response or a resource the client may already have cached, the extra round trip of hints adds little and can even hurt.
Report a problem with this articleOpens a pre-filled issue on GitHub.