Understand the Three Rendering Patterns: SSG, SSR, CSR

Introduction

When building a web page, the first question to address is “How should the page content be generated and delivered to users?” The solutions to this problem are known as “web rendering patterns.”

This question may seem simple, but it involves many different decisions and considerations. Choosing the right web rendering pattern is critical to both user experience (UX) and developer experience (DX). This series introduces different web rendering patterns and compares them to help you choose the right approach for your website.

What Makes Good UX?

Creating a good user experience requires objective metrics to evaluate the page experience and address potential shortcomings. Google’s Core Web Vitals🔗 and related metrics🔗 offer a great way to do this:

What Makes Good DX?

To create a good developer experience and ensure efficient, high-quality development, look for the following architectural characteristics:

⚡

Fast Build Times

The project supports rapid iteration and development

💰

Low Server Operating Costs

Server execution time is minimized and optimized

♻

Easy Rollbacks

Deployments can easily be rolled back to a previous state

🌏

Always Available

Users can visit your website at any time

✨

Dynamic Content

Pages can load dynamic content effectively

🌐

Scalable Architecture

The project can easily scale up or down without running into performance issues

With these metrics and characteristics in mind, we can start comparing the differences and features of various web rendering patterns.

Static Websites

A static website stores prebuilt page documents on a server. When a user requests a page, the server returns the corresponding document without performing any processing—it simply serves the requested file. Because the page content is hard-coded, the main challenge with static websites is that updating dynamic content requires manual editing or using static rendering to generate new documents.

Static Rendering

Static websites can be generated through static rendering. Automated tools called static site generators, such as Jekyll🔗, Hugo🔗, and 11ty🔗, separate data from the presentation layer and use a template engine to generate page documents. This approach is also known as Static Site Generation.

Static website

Compared with manually editing a static website, rendering with a static site generator makes updating and managing pages more efficient. However, there are still a few issues to consider:

🙋🏻‍♀️ Question 1: How Do You Display Dynamic Content?

Since statically rendered page content is generated in advance, displaying additional dynamic content presents a challenge. Here are a few approaches to consider:

🙋🏻‍♂️ Question 2: What If Generation Takes Too Long?

Rendering large numbers of pages can take a substantial amount of time, especially as the page count grows. Since static website pages are generated in advance, every content update requires regenerating “every page on the entire website.” Here is an approach to consider:

Static Rendering with Client-Side Fetching

Building on static rendering, you can use Ajax to send requests with client-side JavaScript, retrieve data, and update the content. This lets you add dynamic content to a static website, but there are still a few issues to consider:

Static website with Ajax

  • LCP - If content does not load promptly, the largest content element may take too long to render

  • CLS - Without an appropriately sized skeleton screen the layout will shift

  • Server operating costs - Dynamic data must be requested every time the page loads
  • Always available - Users must wait for dynamic content to finish rendering before they can see the complete page
  • Scalable architecture - The scalability of the server providing dynamic data needs attention

Server-Side Rendering

With server-side rendering, the server regenerates the page content and returns it to the user each time a page is requested. Since generating pages on demand takes time, server-rendered websites are generally slower than static websites. In return, they make it easy to include dynamic content in pages.

Dynamic website

  • TTFB: Since the server must regenerate the page for each request, the time to first byte will inevitably be longer

  • FCP, LCP, TTI, FID : Waiting for the server to regenerate the page is necessarily slower than serving a prerendered static page, so reaching these milestones may also take longer

  • Server operating costs: Regenerating pages for every request places a heavier load on the server
  • Easy rollbacks: Since pages are generated on demand using current data, restoring a previous page state is more difficult
  • Always available: If the server goes down, no pages can be accessed

Client-Side Rendering

Client-side rendering uses JavaScript to render the entire page in the browser. When a user requests a page, the server returns only an empty HTML file, and client-side JavaScript dynamically generates the page content.

Dynamic website

  • Pay attention to FCP, LCP, TTI, and FID: Because the page must wait for JavaScript to load, the first contentful paint takes longer

Incremental Static Regeneration

Incremental Static Regeneration improves on static site generation by addressing long build times caused by large page counts and the inability to display up-to-date dynamic data. With ISR, only a subset of important pages is rendered in advance; the remaining pages are rendered when users request them. Some implementations also have the server rerender pages at specified intervals, periodically refreshing the content of static pages.

Website using Incremental Static Regeneration

  • Server operating costs: A server must keep rendering new pages in the background, which adds server maintenance overhead compared with fully static generation

Conclusion

The main differences between rendering mechanisms come down to two questions: “Does rendering happen on the server or the client?” and “Are pages rendered in advance or generated dynamically?” The answers to these questions form the core of web rendering patterns. Prerendered pages are generally more SEO-friendly because search engine crawlers can easily interpret ready-made page documents. They also offer better client-side performance, but at the cost of more work on the server.

References