CSR vs SSR vs SSG Explained with a Restaurant Story
Imagine a restaurant. There is a cook, a kitchen, a dining table, and an eater (customer).
We will use this restaurant to understand CSR, SSR, and SSG.
1. CSR - Client Side Rendering
Story
You go to the restaurant.
You sit at the table. But the table is empty.
The waiter brings you raw ingredients:
- vegetables
- rice
- spices
Now you must cook the food yourself at the table.
After cooking, you finally eat.
What happened?
- The kitchen did almost nothing.
- The customer did the cooking.
In web terms
- Browser downloads JavaScript.
- Browser builds the page.
- Then the user sees the content.
Flow
- Browser asks for page.
- Server sends empty page + JS.
- Browser runs JS.
- Page is built in browser.
Example
- React apps (traditional CSR setup)
- Angular apps (default CSR setup)
2. SSR - Server Side Rendering
Story
You go to the restaurant.
The cook prepares the food in the kitchen.
The waiter brings a fully cooked meal to your table.
You can start eating immediately.
What happened?
- Cooking happened in the kitchen.
- Customer only eats.
In web terms
- Server builds the page first.
Flow
- Browser asks for page.
- Server cooks (renders HTML).
- Server sends ready page.
- Browser shows it immediately.
Example
- Angular SSR
- Next.js
- Nuxt
3. SSG - Static Site Generation
Story
Before the restaurant opens in the morning, the cook prepares many plates of food in advance.
When customers come, the waiter instantly gives a ready plate.
No waiting.
What happened?
- Cooking was done earlier.
- Food is already ready.
In web terms
- Pages are generated at build time.
Flow
- Website is built.
- Pages are generated.
- Stored on server/CDN.
- User receives instantly.
Example
- Blog pages
- Documentation sites
- Marketing pages
Simple Comparison
| Type | Who cooks? | When cooking happens |
|---|---|---|
| CSR | Customer | After food arrives |
| SSR | Kitchen | When customer orders |
| SSG | Kitchen | Before restaurant opens |
Super Simple One Line
- CSR -> You cook at the table.
- SSR -> Kitchen cooks after you order.
- SSG -> Kitchen cooked before you arrived.