A page built on the server is visible at once: the markup arrives from the network already complete, and JavaScript loads afterwards and makes it interactive. This mode is built into frameworks such as Next.js and Nuxt, and it is most often chosen for fast first paint and search optimisation.
How it works
On the server, the framework runs the same component code that would run in the browser and assembles an HTML string from it. The browser shows this markup immediately, then downloads JavaScript and performs hydration: it restores the application on top of the ready DOM and attaches event handlers. Before hydration the page is visible but does not yet respond to clicks.
// Node.js serverimport { createSSRApp } from 'vue'import { renderToString } from 'vue/server-renderer' const app = createSSRApp({ data: () => ({ count: 1 }), template: `<button>{{ count }}</button>`})const html = await renderToString(app)// html is the finished markup: <button>1</button>SSR, CSR and SSG
| Mode | Where the HTML is built | What the server needs |
|---|---|---|
| SSR | on the server, on every request | a running application, usually Node.js |
| CSR (client-side rendering) | in the browser, after JavaScript loads and runs | only static file serving |
| SSG | ahead of time, once at build time | serving prebuilt HTML files |
SSR and SSG give equally fast first paint, but SSG is cheaper and simpler to deploy: it suits cases where the content is known at build time and does not change between requests. If a page depends on the user or on data that changes with every request, SSR is the right choice.
Benefits and costs
- Fast first paint: content does not wait for all the JavaScript to load and run, which is noticeable on slow networks and weak devices.
- SEO: a search crawler immediately sees the fully built page rather than an empty shell with a script link.
- Load: rendering the application on the server demands more CPU than serving ready files, so heavy traffic needs a cache.
- Code restrictions: browser APIs such as
windowandlocalStoragedo not exist on the server, and a mismatch between server and client markup breaks hydration. - Infrastructure: a running Node.js server is required, and each request’s response is harder to cache on a shared CDN than SSG’s ready files.
Sources
the term is written from these pagesVerified 9 Nov