logo

kamal's Blog

🀟 Welcome to my tech blog. πŸ’»

About Me

Hey there, I’m Kamal! 🀘 A tech enthusiast with a knack for sharing my mostly silly (and occasionally brilliant 🀯) discoveries in the coding world. This blog is my playground, where I spill the beans on what I’m learningβ€”whether it’s the basics, the latest tech, or random tidbits that might make you go, β€œWait, that’s a thing?” πŸ˜…

Here, you’ll find a mix of flexing, cheeky jokes, and even the occasional β€œmokka” humor to keep things real. Coding is fun, and I write these posts with that same energy! So if you’re having a rough day, stop byβ€”you’ll either walk away grinning or at least wondering, β€œWhat was that?!” 😜

Stick around, laugh a little, learn a lot, and remember: coding is fun, and so is reading about it here! πŸŽ‰

SSR vs CSR: The Interview Question That Made Me Rethink Rendering 🀯

SSR vs CSR: The Interview Question That Made Me Rethink Rendering 🀯

Browser and Server

I was sitting in an interview.

The interviewer asked:

"Can you explain what happens in Server-Side Rendering?"

I confidently replied:

"In SSR, the server renders the component and sends the HTML file to the browser."

I thought I cooked.

The interviewer looked at me.

I looked at the interviewer.

He looked back.

Then he said:

"That's not wrong… but that's not the whole story either."

Ouch.

That sentence sent me on a rabbit hole that ended with me understanding SSR and CSR much better than before.


First, What Is Rendering?

Rendering simply means:

Taking your code and turning it into something the user can see on the screen.

The question is:

Who creates the HTML?

The answer decides whether it's SSR or CSR.


Client-Side Rendering (CSR)

  1. Browser requests the page.
  2. Server sends an almost empty HTML and a JavaScript bundle.
  3. Browser downloads JavaScript.
  4. React executes in the browser.
  5. React creates the UI.
<body>
  <div id="root"></div>
</body>

The actual content doesn't exist initially.

CSR Flow

Browser
   ↓
Request
   ↓
Server sends HTML + JS
   ↓
Browser downloads JS
   ↓
React renders UI
   ↓
User sees content

Why CSR Can Feel Slow

Imagine ordering food and the restaurant says:

  1. Build the kitchen.
  2. Hire the chef.
  3. Buy vegetables.
  4. Then we'll cook.

That's CSR.

The browser has a lot of work before showing content.


Server-Side Rendering (SSR)

This is where my interview answer was incomplete.

The server doesn't simply send HTML.

The server actually runs React.

<Home />

becomes

<h1>Hello World</h1>
<p>Welcome back.</p>

before it even reaches the browser.

SSR Flow

Browser
   ↓
Request
   ↓
Server runs React
   ↓
Generates HTML
   ↓
Sends HTML + JS
   ↓
Browser shows content immediately

The Missing Piece: Hydration πŸ’§

Then my next question was:

If HTML is already there, why do we still need JavaScript?

Because HTML is just the picture.

The page still needs:

  • Click handlers
  • Forms
  • State
  • Interactivity

So the browser:

  1. Displays HTML immediately.
  2. Downloads JavaScript.
  3. React attaches event handlers.

This process is called:

Hydration

HTML arrives
↓
Content becomes visible
↓
JS arrives
↓
React hydrates
↓
Page becomes interactive

This was the detail I missed in the interview.


Visual Comparison

CSR

Request
↓
HTML
↓
Download JS
↓
Execute JS
↓
Render UI


SSR

Request
↓
Server generates HTML
↓
Display UI immediately
↓
Download JS
↓
Hydrate

Benefits of SSR

βœ… Better First Paint

βœ… Better SEO

βœ… Better User Experience

βœ… Better for slower devices


Benefits of CSR

βœ… Great for highly interactive applications

βœ… Lower server work

βœ… Fast client-side navigation


When Should You Use What?

SituationBetter Choice
BlogsSSR
Marketing PagesSSR
SEO-heavy appsSSR
Admin DashboardsCSR
Internal ToolsCSR
Highly Interactive AppsCSR

The Interview Answer I'd Give Today

In Server-Side Rendering, the server executes React components and generates HTML on the server itself. The browser receives this pre-rendered HTML and displays content immediately. Along with the HTML, JavaScript is also sent so React can hydrate the page and attach event handlers, making the page interactive.


Final Thoughts

I wasn't completely wrong.

I was just… incomplete.

And sometimes in tech, that's the difference between:

"Knows React"

and

"Understands React."

As Harvey Specter would say:

"The difference between good and great is attention to detail."

This tiny detail called hydration completely changed my understanding of rendering.

And honestly?

That's the best part of learning.

There is always one more layer beneath what you think you know.


Keep digging. Keep learning. The browser always has another story to tell. πŸš€