No history yet

Mastering Core Web Vitals

Transcript

Beau

Okay, Jo. So, we've talked about the event loop, we've talked about the rendering path, we've even gone deep into React's Fiber architecture. My app *should* be fast now, right? But sometimes... it just... doesn't *feel* fast. How do you even measure 'feel'?

Jo

That's the million-dollar question, isn't it? 'Feels fast' is subjective. And that's exactly why Google created the Core Web Vitals. They're trying to quantify that user experience, that 'feel', with actual, measurable metrics.

Beau

Right, I've heard of these. LCP, FID... CLS? They sound like government agencies.

Jo

Close enough. Think of them as the three pillars of user experience. The first one, LCP, stands for Largest Contentful Paint. It's the simplest to grasp: how long does it take for the biggest, most meaningful piece of content to appear on the screen?

Beau

So, like the giant hero image on an e-commerce site, or maybe the main text block of a blog post?

Jo

Exactly. It answers the user's first question: 'Is this page loading?' If your LCP is slow, the user just sees a blank white screen and thinks the site is broken. In React, this is often a giant image, or maybe a component that has to fetch a ton of data before it can render.

Beau

Okay, that makes sense. Loading. What's next? You said FID?

Jo

FID, or First Input Delay. Though it's now being replaced by a more comprehensive metric called INP, which is Interaction to Next Paint. They both measure the same core idea: responsiveness. When you click a button, how long does it take for something to actually happen?

Beau

Oh, I hate that! You see a button, you click it, and... nothing. You click it again, and then suddenly it fires twice. It's the worst.

Jo

That's exactly what INP measures. It's caused by a busy main thread. Remember our chat about the event loop? If JavaScript is busy doing something—like, say, React is in a long render cycle for a massive component—it can't respond to your click. The click event is just sitting in the queue, waiting.

Beau

So a bad INP is basically React hogging the processor and ignoring the user. Got it. And the last one, CLS?

Jo

Cumulative Layout Shift. This one is about visual stability. Have you ever gone to click a button on a news site, and right as your mouse is about to land, an ad loads above it and pushes the button down, so you click the ad instead?

Beau

Every single day. It's infuriating.

Jo

That's a layout shift. The browser rendered something, then something else loaded—like an image without dimensions or a component that fetched data—and it pushed existing content around. CLS measures how much things jump around on the page unexpectedly.

Beau

Okay, this framework is incredibly useful. Loading, responsiveness, and stability. LCP, INP, CLS. So... how do I see my scores? Where do I find this stuff?

Jo

The simplest way is right in Chrome DevTools. You open it up, go to the 'Performance' tab, and you can record a profile of your page load. It'll give you this massive timeline, a flame chart, but don't get intimidated. There's a 'Timings' section that literally points out your LCP element and any layout shifts.

Beau

And for INP... the responsiveness thing? Can I see that there too?

Jo

Yep. In that same performance profile, you'll see red triangles on tasks that are 'long tasks'—those are your main thread hogs. If you click a button during one of those, you're going to have a bad time. The profiler shows you exactly which JavaScript function is taking all that time.

Beau

Okay, so let's get practical. Say my profiler tells me my INP is terrible because of a huge React component that takes forever to render and blocks clicks. What do I do?

Jo

That's a classic case for code splitting. You probably don't need that giant, complex component the very second the page loads, right? You can use `React.lazy` and `Suspense`.

Beau

I've seen those. So `lazy` basically tells React, 'Don't even bother downloading the code for this component until it's actually needed'?

Jo

Precisely. You wrap the import in `React.lazy`, and then you wrap the component itself in a `Suspense` boundary with a fallback. So your initial JavaScript bundle is much smaller, which improves your LCP because the browser can parse and execute it faster. And since that heavy component's code isn't even running, it can't block the main thread, which helps your INP.

Beau

Two birds with one stone. I like it. What about LCP specifically? Say my biggest element is a huge background image. Code splitting won't help an image, right?

Jo

Right. For that, you need to think about resource prioritization. Is the image compressed properly? Are you using a modern format like WebP or AVIF? But even more importantly, you can give the browser a hint. You can add a `<link rel="preload">` tag to your HTML's `<head>`. This tells the browser, 'Hey, I know you're busy parsing HTML and CSS, but this image is super important. Please start downloading it *now*.'

Beau

So you're basically jumping the queue for critical assets. That's clever. This all feels a bit... reactive, though. Like, I build something, it's slow, I fix it. Is there a way to be proactive?

Jo

Absolutely. That's where a performance budget comes in. Before you write a single line of code, your team agrees on limits. For example, 'Our total JavaScript bundle size shall not exceed 170 kilobytes.' Or, 'Our LCP must be under 2.5 seconds on a slow 3G connection.'

Beau

It's like a financial budget, but for kilobytes and milliseconds. So when a developer wants to add a new, heavy library, it's not a question of 'can we add it,' but 'can we afford it' within our budget?

Jo

You got it. It shifts the entire team's mindset from fixing performance problems to designing for performance from the start. You can even automate it in your CI/CD pipeline to fail a build if a commit pushes you over budget.

Beau

That's a powerful idea. It feels like we've gone from a vague sense of 'slowness' to a concrete set of metrics to measure, tools to diagnose, and strategies—both technical and philosophical—to improve them.

Jo

And that's the whole point. Performance isn't magic. It's engineering. You just need to know what to measure and where to look.