JS Guide
HomeQuestionsTopicsCompaniesResources
BookmarksSearch

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsperformance
PrevNext

Learn the concept

Rendering Strategies & Critical Rendering Path

performance
mid
rendering

What is the difference between SSR, SSG, and CSR?

ssr
ssg
csr
nextjs
rendering
Quick Answer

CSR (Client-Side Rendering) renders in browser. SSR (Server-Side Rendering) generates HTML on each request. SSG (Static Site Generation) pre-builds HTML at build time. SSR/SSG improve initial load and SEO; CSR is simpler but slower first paint.

Detailed Explanation

CSR (Client-Side Rendering):

  • Browser downloads JS, renders page
  • Blank page until JS loads
  • Good for: Dashboards, SPAs

SSR (Server-Side Rendering):

  • Server generates HTML per request
  • Fast first paint, good SEO
  • Higher server load
  • Good for: Dynamic content

SSG (Static Site Generation):

  • HTML generated at build time
  • Fastest performance
  • Cached on CDN
  • Good for: Blogs, marketing sites

Hybrid (ISR):

  • Static + revalidation
  • Best of both worlds
  • Next.js specialty

Code Examples

Next.js rendering methodsJSX
// SSG - Static Site Generation (default for pages without data)
export default function HomePage() {
  return <h1>Home</h1>;
}

// SSG with data
export async function getStaticProps() {
  const posts = await fetchPosts();
  return {
    props: { posts },
    revalidate: 3600, // ISR: Regenerate every hour
  };
}

export default function Blog({ posts }) {
  return posts.map(post => <PostCard key={post.id} post={post} />);
}

// SSG for dynamic routes
export async function getStaticPaths() {
  const posts = await fetchPosts();
  return {
    paths: posts.map(post => ({ params: { slug: post.slug } })),
    fallback: 'blocking', // SSR for new paths
  };
}

// SSR - Server-Side Rendering
export async function getServerSideProps(context) {
  const user = await getUser(context.req.cookies.token);
  return {
    props: { user },
  };
}

export default function Dashboard({ user }) {
  return <h1>Welcome, {user.name}</h1>;
}

Real-World Applications

Use Cases

Building a content-heavy marketing website or blog

Using Static Site Generation (SSG) to pre-render pages at build time, resulting in lightning-fast load times, excellent SEO, and reduced server costs.

Developing an e-commerce platform with dynamic product listings

Employing Server-Side Rendering (SSR) to render initial product pages on the server, improving perceived performance and SEO for constantly changing inventory and personalized content.

Creating an interactive user dashboard or internal admin tool

Where Client-Side Rendering (CSR) is suitable due to high interactivity, frequent data updates, and often being behind authentication, making initial SEO less critical.

Mini Projects

SSR Blog with Next.js

intermediate

Develop a simple blog application using Next.js with Server-Side Rendering (SSR) for initial page loads and data fetching.

SSG Documentation Site with Gatsby/Next.js

intermediate

Build a static documentation website that uses Static Site Generation (SSG) to pre-render all content, ensuring optimal performance and deployability to a CDN.

Industry Examples

Netflix

Netflix uses SSR for its landing pages and initial user interface to improve perceived performance and SEO, ensuring a fast and engaging experience before the full client-side application takes over.

Stripe

Many of Stripe's public-facing marketing and documentation sites leverage SSG for extreme performance and reliability, while their dashboard and payment flows do use a mix of SSR and CSR for dynamic and interactive elements.

Resources

Next.js - Data Fetching

docs

Web.dev - Rendering on the Web

article

Related Questions

What are Core Web Vitals and why do they matter?

junior
metrics

What are the different types of caching for web applications?

junior
caching
Previous
What are common React performance optimization techniques?
Next
What is the difference between debouncing and throttling?
PrevNext