Client-side rendering (CSR) means rendering pages directly in the browser using JavaScript. All logic, data fetching, templating and routing are handled on the client rather than the server.

What is Client Side Rendering?

Client-side rendering (CSR) means rendering pages directly in the browser using JavaScript. All logic, data fetching, templating and routing are handled on the client rather than the server.

In this blog, you will learn everything you need to know about Client-side rendering.

I have already created a video about client-side rendering on my youtube channel called Cules Coding

Everybody talks about client-side rendering, single-page applications. But

  • What problems does it solve?
  • What is it?
  • How it works?

Let's learn the problem with the traditional Server-side rendering. If you don't know what is server-side rendering is, please check this youtube video from my channel first. And if you like the video then don't forget to SUBSCRIBE to my channel.

Also you can check my blog about Server Side Rendering.

Problems with Server-side rendering.

  • Sends Request per page.
  • Heavy loads on the server.
  • Full page reload.
  • Poor UI/UX experience when data changes frequently.

Then what is the solution?

The solution is Client-Side Rendering.

What is Client-Side Rendering?

Client-side rendering (CSR) means rendering pages directly in the browser using JavaScript. All logic, data fetching, templating, and routing are handled on the client rather than the server.

Let's see how Client-side rendering (CSR) works behind the scenes.
  • Browser first sends the request to the server.
  • Server sends an HTML and a CSS response to the client. But the HTML is almost empty. Because all the content is rendered by javascript.
  • Client starts parsing HTML and CSS.
  • After parsing, the parser comes across the javascript script tag at the bottom of the HTML.
  • Then it starts downloading the javascript where content lives. Parsing HTML and CSS is fast but not javascript.
  • A blank page is rendered to the user until the javascript is executed. Because HTML has no content on it.
  • After the javascript is executed, all the necessary content is rendered. Now the application becomes viewable and interactive.

This is a visual representation of the client-side rendering process with react.

Let's see the pros and cons of Client-side rendering (CSR).

Client-side rendering pros

  • Less Frequent server calls. Fetches all needed data at once.
  • Content loading is fast after the initial loading. Because all the needed the javascript file is present on the client.
  • Faster navigation to routes.
  • No page reload.
  • Great performance when data is changing frequently (dynamic web applications).
  • Less Pressure on Server. That's why the server can serve the data quickly.

Client-side rendering cons

  • Bad Seo. Because HTML has no content. The search engines will crawl through your webpage, it will find nothing. So it will give you bad SEO.
  • Might take a huge amount of time when the javascript is heavy. If the application is big then the javascript will be big. Parsing Javascript is slower than HTML and CSS. But it can be optimized with code-splitting. If you want to learn more you can read it from What is Code Splitting.
  • Blank page flickering on initial load. Because of no content on the HTML.
  • Bad performance on slower mobile phones.

Client-side rendering is not always good or bad. It depends on various factors. It is up to you now. Know what your application is and choose what is good for your application.

Shameless Plug

I have made an Xbox landing page clone with React and Styled components. I hope you will enjoy it. Please consider like this video and subscribe to my channel.

That's it for this blog. I have tried to explain things simply. If you get stuck, you can ask me questions.

Contacts

Blogs you might want to read:

Videos might you might want to watch:

Previous PostWhat is Server Side Rendering?