← Back to all articles

Optimizing Core Web Vitals for React Apps

August 16, 2026By Kazi Samiul Haque Adrik

What are Core Web Vitals?

For years, SEO experts tried to guess exactly how Google's ranking algorithm worked. Recently, Google made it explicitly clear: they heavily reward websites that provide excellent user experiences. To measure this objectively, Google introduced Core Web Vitals (CWV).

CWV is a set of three specific metrics that quantify the speed, responsiveness, and visual stability of a webpage. If your React app fails these metrics, your search rankings will plummet, regardless of how good your content is.

Here is exactly how to diagnose and fix the three Core Web Vitals in a modern React/Next.js application.

1. Largest Contentful Paint (LCP)

What it measures: Loading Performance. Specifically, how long it takes for the largest visual element (usually a hero image or a massive H1 tag) to become fully visible on the screen. Passing Score: Under 2.5 seconds.

Why React Apps Fail LCP: In a pure Client-Side Rendered (CSR) React app, the browser downloads a blank HTML file, then downloads a massive JavaScript bundle, executes it, makes an API call, and then finally renders the hero image. This easily takes 4-5 seconds on mobile devices.

How to Fix It:

  • Use Server-Side Rendering (SSR): Frameworks like Next.js or Remix render the HTML on the server instantly.
  • Preload Hero Images: If your LCP element is an image, you must tell the browser to download it immediately, before it even parses the CSS or JS. In Next.js, simply add priority to the <Image> component.
  • Compress Assets: Use WebP or AVIF formats for images. Next.js does this automatically.

2. Interaction to Next Paint (INP)

What it measures: Responsiveness. When a user clicks a button, opens a modal, or types in a form, how long does it take for the UI to visually respond? INP replaced First Input Delay (FID) because it measures all interactions throughout the lifespan of a page, not just the first one. Passing Score: Under 200 milliseconds.

Why React Apps Fail INP: The browser executes JavaScript on a single "main thread". If that thread is blocked doing heavy computations, the browser literally cannot paint UI updates. In React, massive re-renders or processing massive arrays synchronously will freeze the main thread, causing terrible INP scores.

How to Fix It:

  • Yield to the Main Thread: If you have to process 10,000 items, don't do it in one synchronous loop. Use setTimeout or requestIdleCallback to break the task into chunks, allowing the browser to paint UI updates in between.
  • Optimize React Renders: Use useMemo and useCallback to prevent unnecessary re-renders of expensive components.
  • Debounce Inputs: If you have a search bar that filters a list on every keystroke, wrap the filtering logic in a 300ms debounce function.

3. Cumulative Layout Shift (CLS)

What it measures: Visual Stability. Have you ever gone to click a link on a news website, but right as you clicked, an ad loaded, pushing the link down, causing you to click the ad instead? That is a layout shift, and it is the most infuriating user experience on the web. Passing Score: Under 0.1.

Why React Apps Fail CLS: React apps frequently load data asynchronously. If you render a layout, fetch an image from an API, and then inject that image into the DOM without explicitly stating its height/width beforehand, the browser has to push all the content underneath it down to make room.

How to Fix It:

  • Always Define Dimensions: Every single <img>, <video>, or <iframe> in your app must have explicit width and height attributes (or CSS aspect ratios). This allows the browser to reserve the exact amount of space before the image even downloads.
  • Avoid Inserting Content Above: Never dynamically inject banners or alerts at the top of the page after the page has loaded. If you must show an alert, use position: fixed or position: absolute so it overlays the content rather than pushing it down.

Conclusion

Optimizing Core Web Vitals is no longer optional; it is a fundamental requirement for modern web development. By mastering SSR for LCP, main-thread management for INP, and reserved spacing for CLS, you can build React applications that feel blazingly fast and dominate search engine results.

Available for projects
Bangladesh
SSC '26 Grad