# Server-Side Rendering VoltX can render HTML on the server and hydrate it on the client so that the initial paint is fast and SEO-friendly without sacrificing interactivity. ## When SSR Helps - Marketing and content-heavy pages that rely on search indexing. - Dashboards that must show current data immediately on first paint. - Progressive enhancement flows where the page should work without JavaScript. - Latency-sensitive experiences served to slow devices or connections. ## When CSR Is Enough - Highly interactive applications dominated by client-side state. - Authenticated surfaces hidden from crawlers. - Rapid prototypes where deployment speed outweighs initial paint. - Workloads where duplicating rendering logic on the server adds complexity without user benefit. ## Rendering Flow 1. Render HTML on the server and embed serialized state. 2. Ship that HTML to the browser. 3. Call `hydrate()` to attach VoltX bindings without re-rendering. ### Produce Markup on the Server Use `serializeScope()` to convert reactive state into JSON before embedding it in the HTML you return: ```ts import { serializeScope, signal } from "@volt/volt"; export function renderCounter() { const scope = { count: signal(0), label: "Visitors", }; const serialized = serializeScope(scope); return `

${scope.label}

`; } ``` Guidelines: - Every server-rendered root must have an `id`. VoltX looks for ` ``` ```css .loading-overlay { position: fixed; inset: 0; background: white; display: grid; place-items: center; } [data-volt-hydrated] ~ .loading-overlay { display: none; } ``` ### Progressive Enhancement Render functional HTML that works without JavaScript, then let VoltX enhance it: ```html

``` ## Security Checklist - Escape user-generated content in the HTML you render. - Validate JSON before embedding it in `