Understand Server and Client Rendering and Data-fetching

Shadid Haque
InstructorShadid Haque
Share this video with your friends

Social Share Links

Send Tweet
Published 5 months ago
Updated 2 months ago

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.

egghead
egghead
~ 7 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today