Understand Server and Client Rendering and Data-fetching

Shadid Haque
InstructorShadid Haque
Share this video with your friends

Social Share Links

Send Tweet

You'll notice that at the top level, we've set 'use client' for our page. This means that everything on the page is a client component and we miss out on some benefits Next.js gives us by rendering on the server which includes a smaller bundle where sending to the client.

We'll fix this in the next lesson.

[00:00] Back in our code, we're gonna go to the page JS file. So this file lives under source app. And we'll see that we defined use client for this entire component. That means this entire component is going to be rendered in client side. Now there's nothing wrong with this solution. However, we do miss out on some of the performance [00:19] benefit that Next. Js provides through its server side rendering. In Next. Js, server components fetch data on server side. Now they can interact with databases, fetch necessary data, and generate HTML using JavaScript on the server. Now in the sequence diagram here, you can see how the server component works. Now doing this [00:39] improves the application performance. We also deliver a significantly smaller bundle in the client side. Now back in our code, this page component would be much, much more performant if we prefetch all the data in the server side. Only the portion that is interactive should render in client side. So in the next lesson, [00:59] we're going to refactor this component. We're gonna break it down into multiple client components, and we're gonna make this base component a server component.