Put the LCP element on the critical path

React chapter 147 · Web Perf · ch.9 · lazy boundaries, what goes in the first chunk, skeletons · source: Advanced lazy loading: loading critical elements first, preloading lazy chunks

The problem

The whole dashboard page — layout, title, sidebar, widgets — sits inside one lazy() chunk behind one Suspense boundary. Code splitting made the first JS smaller, but the page title (the LCP element) now waits for the slowest chunk. The user stares at a blank area.

The pattern that fixes it

Decide what must paint first and keep it out of the lazy boundary: the layout and the LCP element ship in the main chunk. Lazy-load what is below or beside it, each with a skeleton of its real size. Then preload the next likely chunks after the page is up.

In plain words

Splitting code is choosing an order. Everything inside a <Suspense> boundary waits for its chunk; everything outside it shows as soon as the main bundle runs. Put the most important thing outside.

A restaurant brings bread and water the moment you sit down, and the main course when it is ready. It does not make you sit at an empty table until every dish is cooked.

Terms

critical path
The code and resources that must load before the first meaningful paint.
lazy boundary
lazy(() => import(…)) + <Suspense>. The fallback shows until that chunk loads.
LCP element
The largest text or image in the viewport. DevTools → Performance → LCP → “related node” tells you which.

Going deeper

Find the LCP element first

Record the page in the Performance panel, click the LCP marker and read the related node. Often it is a heading or hero image you did not expect. Trace it to the component that renders it, then trace which lazy boundary it lives under. In one trace, moving AppLayout out of the lazy page dropped LCP ~300 ms; lazy-loading the sidebar saved another 65 ms.

Preload after the critical path

Splitting makes the next navigation wait for its chunk. Fix: after the page renders, import("./settings") the likely next routes (they download at low priority and do not block LCP), or preload from your Link on hover/focus (chapter 100). Frameworks do this per route automatically.

Skeletons and CLS

A fallback that is smaller than the content causes a layout shift when the chunk arrives (chapter 144). Give each skeleton the real dimensions. Prefer one boundary per independent region over one boundary for the page, so a slow widget does not hold back a fast one.

With SSR

With streaming SSR the same thinking applies on the server: content outside Suspense is in the first HTML flush, content inside streams later (chapter 109). Lazy components without SSR support render their fallback into the HTML — never wrap the LCP element that way.

Keep learning

My dashboards

Demo sidebar repeat(3, 1fr) title (LCP element) marks[p] !== undefined && (marks[p] as number) Real life: route-level code splitting where the route component also renders the layout and the page heading. Reload page layout + title inside The title waited for the whole chunk. Loading the page chunk… Everything appears at once, at the very end. The heading is two words of text that could have been on screen immediately. Press Reload page and watch: blank, blank, blank, everything. Moving the layout and title out of the lazy boundary <Suspense> · page chunk title (LCP) nothing paints until 1 chunk main chunk: layout title (LCP) · instant lazy widgets · skeleton LCP no longer waits for any chunk Same page, same chunks. Only where the Suspense boundaries sit has changed. Choosing what sits outside the boundary Move AppLayout and the title into the main chunk. They render as soon as the main JS runs. Sidebar and widgets stay lazy, each behind its own boundary with a same-size skeleton (no layout shift, chapter 144). The page fills in progressively. The heavy parts still load on demand — they just no longer hold back the LCP element. Boundary placement Whole page lazy Layout + title eager, rest lazy Chunk speed Fast network Slow 3G The title is on screen before any chunk arrives. Total load time is the same. What changed is what the user sees first — and LCP measures exactly that. Choose Slow 3G and flip between the two placements. The title time goes from ~3 s to ~0. Watch the skeletons: they are the real size, so nothing jumps when the chunks land.

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.