Choose preload or preconnect
React chapter 151 · Web Perf · resource hints · preload, modulepreload, preconnect, crossorigin · source: preloading, preconnect, fonts, CSS, and waterfall timing
The problem
A slow font is discovered late, so the page adds preconnect to the font file URL and preloads every image and script. The origin hint is malformed, the important file is still discovered late, and speculative downloads compete with the LCP image.
The pattern that fixes it
Use preconnect for a small number of critical cross-origin origins; use preload for an exact resource the current page will soon consume. Match the resource URL, as, type, and CORS mode. For ES modules use modulepreload, and remove hints the page does not use quickly.
In plain words
preconnect prepares the road to another server. preload sends one named delivery down that road early. Neither makes a resource free, so spend the browser’s early bandwidth only on the current page’s critical path.
Preconnect is opening a phone line to a supplier. Preload is placing an exact order before the kitchen asks. Calling every supplier and ordering the whole catalog only creates congestion.
Terms
- preconnect
- Warms an origin by doing connection work such as DNS, TCP, and TLS before its first request.
- preload
- Starts one known high-priority resource for the current navigation before normal discovery.
- fetch destination
- The as value — such as image, font, style, script, or fetch — that tells the browser how the response will be used.
- modulepreload
- The module-aware hint for an ES module and, where supported, its dependency graph.
Going deeper
Preconnect takes an origin, not a file
Use an origin such as https://cdn.example.com, without /fonts/brand.woff2. It is most useful when a required third-party origin is known from the HTML but the first request appears later. The document origin is normally already connected. Too many preconnects waste sockets, CPU, radio time, and battery.
Preload must match the later request
The later request must use the same URL, credentials/CORS mode, and destination. Fonts generally need crossorigin even when the URL looks same-origin. A mismatch can turn one optimization into two downloads; verify one reused request in the Network panel.
What can be preloaded
Common critical destinations are image, font, style, script, and fetch. HTML also defines destinations such as audio, video, track, and worker, but they are rarely first-paint critical. Use modulepreload rather than as="script" for an ES module graph.
Preload is not prefetch
Preload is for a resource needed by this page soon and usually receives high priority. Prefetch is a lower-priority bet for a future navigation. If the current HTML already directly references a stylesheet or hero image, it is discoverable; add a preload only when a trace shows a real discovery delay.
Keep learning
- Previous: Break the render-blocking chain
- Related: lazy + preload
- Related: Request waterfalls
- Related: Yield to main
- Related: CSR blank vs SSR
- Related: React Compiler
- Related: Where LCP time goes
Overview
LCP image Use when the critical image is hidden behind CSS or another late discovery step. <link rel="preload" as="image" imagesrcset="/hero-640.avif 640w, /hero-1280.avif 1280w" imagesizes="100vw" fetchpriority="high"> The href/srcset candidate must match the image the browser actually chooses. WOFF2 font Use for a font needed by above-the-fold text but discovered only after CSS. <link rel="preload" as="font" type="font/woff2" crossorigin> Fonts usually need crossorigin so the preload and CSS font request share one response. Late stylesheet <link rel="preload" as="style" href="/critical.css"> <link rel="stylesheet" href="/critical.css"> Classic script Use for a critical classic script discovered too late, while keeping its execution behavior explicit. <link rel="preload" as="script" href="/checkout.js"> <script defer src="/checkout.js"></script> ES module Use modulepreload for a critical module and its module-aware fetch behavior. <link rel="modulepreload" href="/assets/product-page.js"> <script type="module" src="/assets/product-page.js"></script> Use modulepreload, not preload as script, for a JavaScript module graph. Fetch / JSON Use only when the exact request is predictable and application code will consume it very soon. <link rel="preload" as="fetch" href="/api/product/42" crossorigin> Credentials, CORS, URL, and response use must match the later fetch or the response may not be reused. connect origin critical file unused files tg halo Real life: the font is critical and late, but the team treats every early hint as a free speed boost. Resource hint experiment No hint Preconnect origin Preload exact font Preload everything Early-navigation cost Critical resource ready Unused competing bytes , hot: true, note: <link rel="preload" as="image" href="/gallery-1.avif"> not in viewport <link rel="preload" as="script" href="/admin.js"> not used here <link rel="preload" as="font" href="/brand.woff2"> missing crossorigin <!-- CSS arrives, then discovers the font --> Speculation is competing with the critical request. The exact critical file starts earliest. The road is warm, but CSS still discovers the file. Connection and discovery both begin late. Preconnect removes connection setup from the later request. Preload advances the resource request itself. Both still consume real browser work. Choose Preconnect origin. Connection work moves left, but the font still waits for CSS discovery. Choose Preload exact font. The actual file starts from the document head. Choose Preload everything. Unused transfers steal early bandwidth and make the critical file slower. Preconnect warms an origin. Preload requests an exact resource from that origin. The page later consumes the response. document head sees the future origin is ready file is fetched real request reuses response Choose the smallest hint that fixes the measured delay: an origin hint for connection setup, or a resource hint for late discovery. How early hints become useful work The document head is early enough to act before CSS or JavaScript discovers a critical dependency. Preconnect warms one proven critical cross-origin origin: DNS, TCP, and TLS can happen now. When CSS, HTML, or JavaScript asks for the same resource, the browser reuses the in-flight or cached response. <!-- optional lighter fallback for older/non-critical cases --> What critical resource is discovered late?
Preconnect and preload solve different delays.
Preconnect is reusable connection preparation for an origin. Preload is an early fetch for one resource. Use both only when a critical cross-origin file suffers from both connection and discovery delay. Select each resource type and notice when as, type, crossorigin, or modulepreload changes. In DevTools, enable the Priority and Initiator columns. Keep a hint only if it advances a critical request without creating a duplicate or unused-preload warning.
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- Databases in depth — How a query becomes work. Indexes, isolation, locks, and the plans that explain why a page is slow — not an ORM tour.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.