Server Side Rendered Page with Data

When should you server-side render a page?

A good way to judge if server-side rendering a page is the right page type for you is to ask yourself a few questions.

  • Will the data change often?
  • Is the most recent data important?
  • Will the page use route parameters in order to determine which data it will retrieve?

If you answered yes to any of those questions, you will need to server-side render the page.

When HTML gets generated

Lastly, if you remember from a previous lesson, statically generated pages are created at build time. That means that when someone requests that page, the server has the HTML in hand and serves it to the user right away. When you are server-side rendering a page, the server creates the HTML for every request.

NOTE: In my experience, the server-side rendered pages are extremely fast. Perhaps not as fast as a statically generated page, but you should not shy away from using this page type if your application requires using it.

Easy use of server-side rendering

I am going to show you real quickly how easy it is to change a statically rendered page with data to a server-side rendered page.

Your index.js page, which is also the home page, is statically generated with data. And that’s because you wanted to make a default giphy search for cats. It was not really important if you had the most updated information, and using a statically generated page provided better performance than requesting giphy API on each page load. For this example, you are going to switch your index.js to a server-side rendered page. It’s actually really easy to do. Check out this piece of the current code:

Get hands-on with 1200+ tech skills courses.