CSR vs SSR

SamSam
2 min read

Overview

React (CSR) Flow

  1. Initial Server Response
<!DOCTYPE html>
<html>
  <head>...</head>
  <body>
    <div id="root"></div>
    <script src="/static/js/bundle.js"></script>
  </body>
</html>
  1. Subsequent Requests
  • Browser requests JavaScript bundles (usually split into chunks):

    • main.chunk.js (application code)

    • vendor.chunk.js (dependencies)

    • runtime.js (webpack runtime)

  • All static files served from /build directory

  • Client-side rendering begins only after JS loads

  • Data fetching starts after JS execution

Next.js (SSR) Flow

  1. Initial Server Response
<!DOCTYPE html>
<html>
  <head>
    <script src="/_next/static/chunks/main.js" defer></script>
  </head>
  <body>
    <div id="__next">
      <!-- Fully populated HTML content -->
      <!-- Server Component Payload -->
    </div>
  </body>
</html>
  1. File Structure After Build
.next/
  ├── server/
  │   ├── pages/
  │   │   └── [page].html
  │   └── chunks/
  ├── static/
  │   ├── chunks/
  │   ├── css/
  │   └── media/

Key Differences in File Serving

  1. React (CSR)

    • Serves static files from single build directory

    • Initial HTML is empty

    • Requires complete JS load for any content display

    • All routing handled client-side

  2. Next.js (SSR)

    • Serves from .next directory with specialized structure

    • Initial HTML contains full content

    • JS files load for hydration but content visible first

    • Server handles routing and generates specific HTML per route

Performance Implications

  • React: Larger initial JavaScript bundle, slower first contentful paint

  • Next.js: Faster first contentful paint, smaller initial JS payload, better SEO

Browser Processing Order

React:

  • Empty HTML → 2. JS Bundles → 3. Render Content → 4. Data Fetching

Next.js:

  • Full HTML → 2. Display Content → 3. JS for Hydration → 4. Interactive

This comprehensive approach shows why Next.js typically provides better initial load performance and SEO capabilities, while React's CSR approach might be more suitable for highly interactive applications where initial load time is less critical.

1
Subscribe to my newsletter

Read articles from Sam directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sam
Sam