Understanding Web Rendering Methods - CSR, SSR, SSG, and ISR

A comprehensive comparison of different web rendering approaches

Featured image



🎯 Overview

Web rendering is the process of generating visual content from web code, including HTML, CSS, and JavaScript. Let’s explore the four main rendering approaches: CSR, SSR, SSG, and ISR.


💻 Client-Side Rendering (CSR)

Process:

  1. Browser downloads minimal HTML
  2. JavaScript loads and executes
  3. UI renders dynamically
  4. Handles user interactions

Advantages

Disadvantages

sequenceDiagram participant User participant Browser participant Server participant API User->>Browser: 🌐 Request Page Browser->>Server: 📡 Load Static HTML/JS Server-->>Browser: 📦 HTML/JS Bundle Browser->>API: 🔄 Fetch Data (AJAX/Fetch) API-->>Browser: 📊 JSON Data Browser->>User: 🖥️ Rendered Content


🖥️ Server-Side Rendering (SSR)

Process:

  1. Server processes request
  2. Generates complete HTML
  3. Sends rendered page
  4. Browser displays content

Advantages

Disadvantages

sequenceDiagram participant User participant Browser participant Server participant Database User->>Browser: 🌐 Request Page Browser->>Server: 📡 Request HTML Server->>Database: 📂 Fetch Data Database-->>Server: 📦 Return Data Server->>Browser: 🏗️ Rendered HTML Browser->>User: 🖥️ Display Page


📄 Static Site Generation (SSG)

Process:

  1. Pages built at build time
  2. Pre-renders all HTML/CSS/JS
  3. Serves via CDN
  4. Instant page loads

Advantages

Disadvantages

graph LR A[🛠️ Build Time] --> B[📂 Fetch Data] B --> C[🏗️ Generate Static Pages] C --> D[🗄️ Store on CDN] D --> E[🌐 User Requests Page] E --> F[🚀 Serve Pre-built Page]


🔄 Incremental Static Regeneration (ISR)

Process:

  1. Initial static generation
  2. Background revalidation
  3. Selective page updates
  4. Cached delivery

Advantages

Disadvantages

graph LR A[🌐 User Requests Page] --> B{🗂️ Is Page Cached?} B -- Yes --> C[📄 Serve Cached Page] B -- No --> D[📡 Fetch Data from API] D --> E[📝 Generate Static Page] E --> F[🗄️ Cache the Page] F --> C



📊 Rendering Methods Comparison

🔑 Feature ⚡ CSR 🌐 SSR 🏗️ SSG 🚀 ISR
⏳ Initial Load 🐢 Slow ⚡ Fast 🚀 Fastest ⚡ Fast
🔍 SEO ❌ Poor ✅ Good 🌟 Excellent ✅ Good
🔄 Dynamic Content 🌟 Excellent ✅ Good ❌ Poor ✅ Good
🖥️ Server Load 🟢 Low 🔴 High 🟢 Lowest 🟡 Medium
🛠️ Build Time ⏳ N/A ⏳ N/A ⌛ Long ⏳ Medium


📌 Use Cases Table

🔑 Feature ⚡ CSR 🌐 SSR 🏗️ SSG 🚀 ISR
📦 Use Case SPA (Single Page Application), Dashboards News websites, e-commerce product pages Blogs, Documentation sites E-commerce product pages with frequent updates
🛠️ Tools/Frameworks React, Angular, Vue Next.js, Nuxt.js Gatsby, Hugo, Jekyll Next.js (ISR), Nuxt 3
🔐 Security Exposed API keys risk Better control over data flow Safe with minimal server interaction Cache invalidation risks



📚 Reference