Both server-side rendering (SSR) and static site generation (SSG) involve generating HTML on the server. However, it's most accurate to view them as related but distinct techniques within the broader category of server-side content generation.
The key difference is timing:
- SSG pre-renders HTML at _build time_, serving pre-generated files.
- SSG allows serving pre-built static files from a CDN.
- SSR generates HTML _dynamically_ on each request, providing up-to-date, personalized UX.
- SSR may have slightly higher latency due to on-demand processing.
SSR vs SSG:
- SSG is ideal for static content with infrequent updates, providing fast load times.
- SSR excels with dynamic content that changes frequently.
- Both SSG and SSR are SEO-friendly since they quickly generate HTML outputs on the server, enabling search engines to crawl and index the pages easily.
See also: [[Server-side rendering vs Client-side rendering]]