Server-Side Rendering (SSR)
Server-Side Rendering (SSR) generates the full HTML for a page on the server in response to each request. The browser receives a complete page that can be displayed immediately, without waiting for JavaScript to download and execute.
SSR improves perceived performance (users see content faster), SEO (search engines receive complete HTML), and social sharing (crawlers can read meta tags and content). After the initial HTML loads, JavaScript "hydrates" the page to make it interactive.
Modern SSR frameworks include Next.js (React), Nuxt (Vue), SvelteKit (Svelte), and Astro (multi-framework). These support hybrid rendering modes — some pages can be SSR, others static (SSG), and others client-side rendered (CSR).
Trade-offs include increased server load (every request requires rendering), higher Time to First Byte (TTFB) compared to static files, and hydration overhead. Streaming SSR (supported by React 18+) mitigates some of these by sending HTML in chunks as it's rendered.
How it works
On every request the server runs the page's code with that request's inputs (URL, cookies, database results) and returns finished HTML. The article "Rendering on the Web" on web.dev defines it as rendering an app on the server to send HTML, rather than JavaScript, to the client.
If the page has interactive parts, their JavaScript loads afterwards and hydrates the HTML, attaching event handlers and state. Until that finishes, controls can look ready but not respond.
The same article lists the trade-offs: SSR gives a fast First Contentful Paint and less main-thread blocking than client-side rendering, but generating pages on the server can increase Time to First Byte. Streaming server rendering sends HTML in chunks as it is produced, so the browser can start painting before the whole page is ready.
Because the work happens per request, output can be personalised and is always current, but the server has to be sized for traffic and caching becomes an important lever. In Astro, pages are prerendered at build time by default; a page opts into on-demand rendering with export const prerender = false, which requires a server adapter.
Example
An Astro page rendered on every request, reading a cookie that only exists at request time.
---
// src/pages/orders.astro
export const prerender = false; // render on each request (needs an adapter)
const session = Astro.cookies.get('session')?.value;
const res = await fetch('https://api.example.com/orders', {
headers: { Authorization: `Bearer ${session}` },
});
const orders = await res.json();
---
<ul>
{orders.map((o) => <li>Order {o.id}: {o.status}</li>)}
</ul> Each visitor gets HTML listing their own orders, already in the response body, so it is visible before any JavaScript runs. Remove the prerender line and Astro would try to build this page once at build time, when there is no visitor and no cookie, which is why per-user pages need SSR.
Common confusion
What is the difference between server-side rendering and static site generation?
Both send ready-made HTML. The difference is when it is produced: SSR renders on each request, so it can use request data and is always fresh; static generation renders once at build time, so pages are served as files with consistently fast TTFB but only change when the site is rebuilt.
Does server-side rendering mean the page ships no JavaScript?
No. SSR only decides where the first HTML comes from. In frameworks that hydrate the whole page, the browser still downloads and runs the JavaScript for every component so it can hydrate. Islands-style frameworks such as Astro ship no JavaScript by default and hydrate only the components marked as interactive.
Related tools & demos
- Static Site Generation (SSG) The build-time alternative.
- Hydration The step that makes server-rendered HTML interactive.
Further reading
- Rendering on the Web (Addy Osmani, Jason Miller) web.dev
- On-demand rendering Astro documentation
Want to learn more?
Explore more developer terms or read in-depth articles on the blog.
Browse all terms