FMTechnical notesPortfolio
Back to the blog

Next.js · Advanced

Next.js in depth: CSR, SSR, and static generation

Next.js offers several rendering strategies because pages solve different problems. Ask when the data exists and who needs the first HTML.

After reading this
  • Tell CSR, SSR, and SSG apart
  • Understand the Pages Router
  • Choose rendering by need
01 / 03

Three strategies, different costs

CSR obtains data in the browser. SSR generates HTML per request. SSG generates HTML during the build. One application can combine them.

  • CSR: private dashboards and highly dynamic state.
  • SSR: public data that changes per request.
  • SSG: documentation, portfolios, and articles known at build time.
02 / 03

The Pages Router

Each file under pages defines a route. _app wraps pages and keeps shared UI. _document customizes the server HTML document and does not handle interaction. Dynamic routes use brackets.

tsx
// pages/blog/[slug].tsx
export const getStaticPaths = async () => ({
  paths: posts.map(({ slug }) => ({ params: { slug } })),
  fallback: false,
});

export const getStaticProps = async ({ params }) => ({
  props: { post: findPost(params.slug) },
});
03 / 03

Choose with evidence

If content exists at build time, SSG delivers fast, cacheable HTML. If it depends on a session, solve it in the client or server according to sensitivity. Do not use SSR by reflex.

Render strategy● interactive
DATAHTMLHYDRATEINTERACT
Practice

Choose rendering

Pick a strategy for a landing page, bank dashboard, hourly catalog, and article detail.

Show a hint

Consider privacy, change frequency, SEO, and regeneration cost.