So what I want to talk to you about today is speed, and specifically the Core Web Vitals and how to get it to Core Web Vitals as high as possible. Turns out the answer is relatively simple but hard to do, ship less JavaScript. And Google cares about it a lot, and as a result they created these Core Web Vitals metrics that they track and perform.
But it turns out that as our websites are getting more and more popular and more complicated, the amount of JavaScript we're shipping to the client is slowly increasing over the years, as you can see over here. So as the number of amount of JavaScript is increasing, it makes it harder and harder to actually pass Core Web Vitals. And you can see that most of the websites that are kind of out there actually have trouble passing Core Web Vitals. And even Amazon that cares very deeply about performance, and they are some of the most web performance websites out there, is having trouble passing these scores. And it really comes down to the amount of JavaScript that's being shipped to the client.
And so let's start with a very simple example. And let's build a counter example. Well, counter will probably look something like this. You know, we have a button that you hit plus one, and there's a count and it increments the value. And so this is kind of the simplest possible application that you can think of. But I don't think this is a really representative of the real world app, because in this particular application we have our mutation, which is your listener, our state, which is the current count, and the rendering, which is the binding of what the value is, all inside of a single component. And realistically, usually their mutation, the state and a rendering are separated into separate components.
And so let's look at that as a more realistic example. Or we break this thing up. And so an example of this would look something like this, where you have the counter component that is at the root, and it contains two smaller components, the action and the display, where the counter contains the state and the action has the listener, and the display shows just the current count. Now, even that is not actually quite realistic, because typically we have additional things like we have AppRoot, we have extra wrappers that you use for the purposes of the layout of the components and so on. And all of these extra things actually make it more realistic to what the actual application is. So here's what this would look like.
As you can see, we still have a counter, but now our action is wrapped in an additional component and so is our display. And the reason I'm showing this is because you need to get data through these additional wrappers, and it will have effect in the way the application runs. And finally, let's introduce an action item and a display icon. And the idea behind those things is that there are essentially leaps. There are components that don't do anything, but oftentimes we have these components in our application. So a more realistic example of what an application really looks like is a mixture of these app components, the counter, the different kind of wrappers, finally a place where we actually perform some of the actions, and a location where we actually update the UI. You can think of the performing of the action as the buy button on a page, and you can see the count as the showing the current shopping cart on the UI. So really, what we have is we have the situation where the mutation and the display are actually far apart from each other, and they have to share a common root component, the least common denominator kind of root component, which encompasses both, which contains the state, and so the state is then passed down to both of these locations. Now, the thing is that you would think that for such a simple application, the only code that you have to download to the client is really just the mutation action, maybe the state and maybe the display.
Comments