DEV Community

Cover image for SSR and CSR Explained
Sushant Babu Prasai
Sushant Babu Prasai

Posted on

SSR and CSR Explained

In the world of modern web development, how a website renders content can make a big difference in terms of performance, user experience, and search engine optimization(SEO).

Two popular approaches for rendering web pages are Server-Side Rendering (SSR) and Client-Side Rendering (CSR). SSR renders pages on the server, delivering fully formed HTML to the browser, while CSR relies on the browser to dynamically generate content using JavaScript.

It's like choosing between instant noodles (quick and ready to eat) and a gourmet meal kit (takes more prep but oh-so-customizable). Let's dive in and see what makes each of these rendering rockstars tick!

Server Side Rendering (SSR)

Server-Side Rendering (SSR) is when a web page is generated on the server and then sent to the client (browser) as a fully formed HTML page. This means that the browser doesn’t have to do any heavy lifting when it first receives the page—everything is ready to go! SSR is great for improving SEO and initial load times because the content is visible right away, but it can lead to slower subsequent interactions as the server needs to generate the page on each request.

Image description

Steps of SSR (a.k.a. “Instant Gratification”)

  1. Request HTML - The server builds and sends a complete page.

  2. Fetch JavaScript - The browser grabs scripts to enable interactivity.

  3. Hydration- The static page becomes interactive once JavaScript kicks in.

Client Side Rendering (CSR)

Client-Side Rendering (CSR) flips the script. Instead of sending a complete HTML page, the server provides a minimal HTML shell (Incorrect HTML), and the browser (with some help from JavaScript) does the work of rendering the page. This approach allows for faster interactions after the initial load, but that first load might feel slower because the browser must fetch and execute JavaScript before displaying anything. CSR shines in apps where interactivity and speed of user interactions are the priority, like Single Page Applications (SPAs).

Image description

Steps of CSR (a.k.a. “The Long Wait”)

  1. *Request HTML *– The browser gets an empty skeleton page.
  2. Fetch JavaScript – The browser grabs the scripts to build the page.
  3. Execute JavaScript – The page starts building, showing loading spinners.
  4. Fetch data – Real content comes in from APIs or servers.
  5. Display page – The page is fully ready to use!

So, what's the final word? Well, if you're building a site that needs to impress search engines and load like lightning from the get-go, SSR is like having a personal chef serve up a fully cooked meal. On the flip side, if your app is more about interactivity and dynamic content, CSR is like a DIY (Do It Yourself) meal kit takes a bit more effort upfront, but once it's ready, it’s fast and flexible.

Ultimately, the choice between SSR and CSR depends on what you’re serving up: quick, static content or a fully interactive user feast. And hey, if you're feeling fancy, why not mix and match both? After all, why choose when you can have the best of both worlds!

Top comments (1)

Collapse
 
digitalrisedorset profile image
Herve Tribouilloy

Great illustration, thanks for sharing. I'll put more thoughts on it but this content is very easy to read and help to get the grasp of both concepts CSR and SSR in one page.