JS Guide
HomeQuestionsSearchResources
Search

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

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsperformance
PrevNext
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 methods
// 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>;
}

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?