Server Side Rendering Fundamentals
Server Rendering Lifecycle
The Two Paths of a Web Request
When you type a URL into your browser and hit Enter, you kick off a conversation between your computer (the client) and a remote computer (the server). The goal is simple: get a webpage to display on your screen. But how that page is assembled can happen in two fundamentally different ways: on the client or on the server.
Client-Side Rendering (CSR) is like getting a flat-pack furniture kit. The server sends your browser a nearly empty HTML file, along with all the JavaScript instructions needed to build the page. Your browser then becomes a workshop, executing the JavaScript to assemble the HTML, fetch data, and render the final page. This can result in a brief 'blank screen' moment while the assembly is in progress. Everything happens in your browser.
Server-Side Rendering (SSR), on the other hand, is like ordering pre-assembled furniture. When your browser makes a request, the server does all the work upfront. It runs the application logic, fetches the necessary data from databases or APIs, and constructs the full HTML of the page. It then sends this complete, ready-to-display HTML file to your browser. The page appears almost instantly because the browser's only job is to show what it received.
This fundamental difference in assembly has a major impact on performance metrics. With SSR, because a fully formed page arrives, the (FCP) is very fast. Users see content immediately. However, since the server is doing work before it sends anything, the Time to First Byte (TTFB) can be higher. It's a trade-off: a slightly longer wait for the first piece of data, in exchange for an instantly visible page once it arrives.
The Server's Workshop
So how does a server build a webpage? Traditionally, servers just served static files. But to generate HTML dynamically, the server needs an environment to run the application's code. This is where come into play for modern JavaScript applications.
When a request for a page hits a server running a Node.js application, the framework intercepts it. It maps the URL to the correct components, runs data-fetching functions to get content, and then renders the entire component tree into a single HTML string. This string, containing all the text and structure, is what's sent back to your browser.
Server-side rendering (SSR) is the process of rendering web pages on the server and sending fully-rendered HTML to the client.
One Language, Two Environments
One of the most powerful concepts enabling modern SSR is 'isomorphic' or 'universal' JavaScript. This means the same code can run in two different environments: the Node.js environment on the server and the browser environment on the client. Think of a component that displays a user's profile. On the server, that component's code is run to generate the initial HTML markup. The server essentially takes a snapshot of what the component should look like with the data it fetched.
Then, once that HTML arrives in the browser, the same JavaScript code runs again. This time, instead of re-creating the HTML from scratch, it attaches event listeners and makes the page interactive. This process is called — it takes the 'dry' static HTML from the server and brings it to life with client-side interactivity. The server 'pre-seeds' the document with the initial state and content, which the client-side app then picks up and takes over.
This universal approach eliminates the jarring 'blank screen' effect common in pure Client-Side Rendered Single Page Applications (SPAs). Users get meaningful content right away, while still benefiting from a rich, interactive experience once the page fully loads.
Time to test your knowledge on how servers build and deliver web pages.
If Server-Side Rendering (SSR) is like ordering pre-assembled furniture, what is Client-Side Rendering (CSR) analogous to?
In Server-Side Rendering (SSR), which of the following performance trade-offs is most accurate?
