Skip to content

⚑ SSR vs SSG vs ISR in React (Next.js)

  • Page is render on server for every request.
  • Always fresh data, but slower than static.
  • βœ… Use case: Pages with personalized / frequently changing data (e.g., dashboards, logged-in profile, admin pages).
  • Example :
pages/index.js
export async function getServerSideProps() {
const res = await fetch("https://api.example.com/data");
const data = await res.json();
return { props: { data } };
}
  • πŸ‘‰ Each request β†’ Next.js runs getServerSideProps β†’ HTML generated β†’ sent to browser.
  • Page is built at compile time (build step).
  • Super fast (just HTML + JS served from CDN).
  • Data is frozen at build time.
  • βœ… Use case: Pages with rarely changing data (e.g., blog posts, docs, landing pages).
  • Example :
pages/index.js
export async function getStaticProps() {
const res = await fetch("https://api.example.com/data");
const data = await res.json();
return { props: { data } };
}
  • πŸ‘‰ Runs once during build β†’ HTML + JSON cached on CDN β†’ instant load.
  • Hybrid between SSG + SSR.
  • Page is built at built time, but can be re-generated in the background after a set time.
  • Users always get fast static page, but data updates periodically.
  • βœ… Use case: Pages with semi-dynamic data (e.g., product listings, news site).
  • Example :
pages/index.js
export async function getStaticProps() {
const res = await fetch("https://api.example.com/data");
const data = await res.json();
return {
props: { data },
revalidate: 60, // re-generate every 60s
};
}
  • πŸ‘‰ First request β†’ old cached page served.
  • πŸ‘‰ Background β†’ page regenerated.
  • πŸ‘‰ Next user β†’ gets updated page.
FeatureSSR (Server-Side)SSG (Static Site)ISR (Incremental Static)
Render timingEvery requestAt build timeAt build + revalidated later
Performance❌ Slower (server work)βœ… Fast (CDN cached)βœ… Fast (CDN cached + refresh)
Data freshnessβœ… Always fresh❌ Stale if data changes⚑ Semi-fresh (updates on interval)
Use casesDashboards, auth pagesBlogs, docs, marketingProduct pages, news feeds
  • β€œSSR fetches fresh data on each request but is slower.”
  • β€œSSG pre-builds pages at compile time for maximum speed, but content is frozen until rebuild.”
  • β€œISR combines both: pages are cached like static but periodically refreshed in the background.”