Performance · React · Core Web Vitals · SEO
Core Web Vitals for a Heavy React App: Fixing LCP, INP and CLS
Practical techniques to improve LCP, INP and CLS in a JavaScript-heavy React app: a static first paint, deferred CSS and bundles, and lazy-loaded features.
This site is an OS-style React app with games, windows, animated backgrounds and a chat assistant. In other words, a strong candidate for a "bad example" of performance. Even so, it was possible to keep its mobile Lighthouse performance score high. This article explains the techniques in a way you can apply to other React projects.
Three metrics, three questions
Core Web Vitals are the three metrics Google uses to measure user experience:
| Metric | Question | Good threshold |
|---|---|---|
| LCP (Largest Contentful Paint) | How quickly did the main content appear? | ≤ 2.5 s |
| INP (Interaction to Next Paint) | How fast does it respond to taps and clicks? | ≤ 200 ms |
| CLS (Cumulative Layout Shift) | Does content jump around while loading? | ≤ 0.1 |
INP replaced FID in March 2024 and is much stricter: it measures every interaction on the page, not just the first one.
LCP: free the first paint from JavaScript
In a typical React app the browser downloads HTML, then CSS, then hundreds of kilobytes of JavaScript, runs it, and only then draws something. On a slow phone that is several seconds.
1. A static first screen
The "boot" screen you see when this site opens is pure static HTML with inline CSS. The browser paints it right away without waiting for JavaScript, and that text is the LCP element. When React loads, the boot screen fades out.
The equivalent in your project: put the first view of your app shell in the HTML. It can be a header, a skeleton, or server-rendered content.
2. Load the main CSS without blocking render
Vite's main CSS file normally blocks rendering. Since the first screen has its own inline styles, the main CSS can be preloaded and applied when ready:
<link rel="preload" as="style" href="/assets/index.css"
onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="/assets/index.css"></noscript>
Keeping the app root hidden until the stylesheet has loaded prevents a flash of unstyled content.
3. Start the app bundle after the first paint
This was the most effective step: instead of referencing the main module directly in the HTML, a tiny loader adds it after the first frame:
<script>
const start = () => {
const s = document.createElement('script');
s.type = 'module';
s.src = '/assets/index.js';
document.head.appendChild(s);
};
document.hidden ? start() : requestAnimationFrame(() => setTimeout(start, 0));
</script>
The requestAnimationFrame plus setTimeout pair lets the browser paint the boot screen first and only then start downloading JavaScript. On this site a small Node script does the rewrite after each build, so Vite's hashed file names always stay correct.
4. Prioritise the LCP image
If your LCP element is an image: give it fetchpriority="high", don't lazy-load it, and serve it at the right size in a modern format (AVIF/WebP). The profile photo on this site's static pages uses fetchpriority="high".
INP: keep the main thread free
INP suffers when the main thread is busy with something else at the moment the user taps.
- Code splitting: every app window loads as its own chunk with
React.lazy. The calculator, games or gallery aren't even downloaded until the user opens them.
const Gallery = lazy(() => import('./apps/Gallery'));
- Split vendor chunks: React and the i18n libraries live in separate chunks, so users don't re-download them when app code changes.
- Break up heavy work: split long loops into pieces and let the browser breathe in between (
scheduler.yield()where supported, otherwisesetTimeout). - Mind your animations: background animations should run on
canvaswithrequestAnimationFrameand pause while the tab is hidden. Respectingprefers-reduced-motionis a win for accessibility and performance alike.
CLS: reserve space
- Give every
<img>awidthandheight, so the browser reserves its space before it arrives. - Use
font-display: swapfor web fonts, with fallback fonts of similar metrics. - Reserve room for late banners, cookie notices and ads, or show them in a way that doesn't push content (for example, fixed position).
No improvement without measurement
- Lab data: Lighthouse and PageSpeed Insights show the effect of a change quickly. Use the mobile profile and run several times; a single run can mislead.
- Field data: real user experience comes from the Chrome UX Report (CrUX) and the Core Web Vitals report in Search Console. Google uses field data for ranking.
- Guard it in the build: this site's build includes a check that the main CSS doesn't block rendering and that the loader is in place, so the next change can't silently break performance.
Conclusion
Even a heavy React app can feel fast when it loads in the right order: static HTML first, then styles, then JavaScript, and that only as it is needed. The server-side counterpart is in the Cloudflare Pages and Workers article, and search and AI visibility in making your website AI-agent ready.