Vue3 Fundamentals · Modern Vue (3.5 / 3.6)

Server-side rendering basics

Server-side rendering basics

A client-rendered Vue app ships an empty page and fills it in after the JavaScript loads. On a slow connection the user stares at a blank screen, and a crawler may see nothing at all.

Server-side rendering (SSR) flips the order. The server runs your components, turns them into an HTML string, and sends that string with the page. The browser paints real content immediately, then Vue takes over.

Two pieces make it work. On the server you build the app with createSSRApp instead of createApp, and render it with renderToString from vue/server-renderer:

import { createSSRApp } from 'vue';
import { renderToString } from 'vue/server-renderer';

const app = createSSRApp(App);
const html = await renderToString(app);

The browser then hydrates that HTML: Vue attaches to the existing DOM instead of rebuilding it. For hydration to work, the markup the server produced must match what the client would render on its first pass. If they differ — a random value, a Date.now(), a browser-only branch — Vue warns about a hydration mismatch and repairs the tree, which costs the speed you were after.

SSR buys a faster first paint and indexable content. It costs a server that runs Vue, and the discipline to keep server and client output in step.

You are about to answer a short quiz on server-side rendering.

  1. Server-side rendering sends an HTML string with the first response, so content paints before the JavaScript loads.
  2. On the server you build the app with ___ instead of `createApp`.
  3. You turn the app into an HTML string with `renderToString` from `vue/___`.
  4. Hydration means Vue attaches to the server-rendered DOM instead of rebuilding it.
  5. A hydration mismatch happens when the server markup and the client's first render disagree.
  6. SSR removes the need for a server to run Vue.