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:
Time to First Byte
Measures the time between requesting a resource and receiving the first byte of the response during page loading
First Contentful Paint
Measures how long it takes for the first content to appear during page loading
Largest Contentful Paint
Measures how long it takes for the largest content element to first appear during page loading
Time to Interactive
Measures how long it takes for a page to become interactive
Cumulative Layout Shift
Measures how often page content shifts position
First Input Delay
Measures how long a page takes to respond to the user's first interaction
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.
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:
- Use a server to dynamically generate and respond to each page request: Server-Side Rendering (SSR)
- Load content dynamically on the client: Static Rendering with Client-Side Fetching
🙋🏻♂️ 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:
- Have the server generate pages only when they are requested: Incremental Static Regeneration
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:
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.
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.
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.
- 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
- Rendering Patterns - patterns.dev
- Rendering Patterns - JavaScript Patterns
- 10 Rendering Patterns for Web Apps - Beyond Fireship
- Rendering on the Web