Full answer
Server-side rendering (SSR) means the server sends finished HTML for the first view, so users and search engines see content before the JavaScript loads. In the Angular world this was called Angular Universal.
History in short:
- Early versions: Universal was a separate project and a separate set of packages (
@nguniversal/express-engineand others). You wrote aserver.tsfile, an extraAppServerModule, and extra build targets. - Hydration: before Angular 16, the browser threw the server HTML away and rendered again, which caused a flash and wasted work. Angular 16 introduced hydration as a preview, and Angular 17 made it stable.
provideClientHydration()reuses the server DOM. - Angular 17: Universal was folded into the CLI.
ng new --ssrandng add @angular/ssrset it up. The newapplicationbuilder (esbuild and Vite) builds browser and server code, and supports prerendering (static site generation) at build time. - Angular 18 and 19: event replay (clicks made before hydration finished are replayed), incremental hydration with
@defer (hydrate on viewport), route-level render modes in the server routes file (RenderMode.Server,ClientorPrerender) and a new request handling API (AngularNodeAppEngine,AngularAppEngine) that also runs on edge platforms. Several of these were preview features and became stable by Angular 20.
What the modern setup has:
@angular/ssrand@angular/platform-server.app.config.server.tsthat merges the app config withprovideServerRendering().app.routes.server.tswith a render mode for each route:Prerenderfor pages that rarely change,Serverfor personal pages,Clientfor dashboards behind login.provideClientHydration(withEventReplay())in the browser config.TransferState(automatic forHttpClientGET requests) so data is not fetched twice.
Rules of thumb: use prerendering when content is the same for everybody, SSR when content changes per request, and plain client rendering when SEO and first paint do not matter. Keep browser-only code in afterNextRender, and avoid direct window access.
Interview tip: say "Universal is now part of Angular itself (@angular/ssr)", and name hydration as the key change.
import { RenderMode, ServerRoute } from '@angular/ssr';
// app.routes.server.ts
export const serverRoutes: ServerRoute[] = [
{ path: '', renderMode: RenderMode.Prerender }, // same for everybody
{ path: 'courses/:id', renderMode: RenderMode.Server }, // changes per request
{ path: 'dashboard', renderMode: RenderMode.Client }, // behind login, no SEO
{ path: '**', renderMode: RenderMode.Server },
];
// app.config.server.ts (outline):
// const serverConfig = { providers: [provideServerRendering(withRoutes(serverRoutes))] };
// export const config = mergeApplicationConfig(appConfig, serverConfig);
// app.config.ts: provideClientHydration(withEventReplay())Angular 20.3 with `@angular/ssr` 20.3, type-checked. The server routes file shows the real API shape. The server was not started here, so no page was rendered.
Key points
- Universal was a separate SSR project. Since Angular 17 it is part of the CLI as `@angular/ssr`.
- Hydration reuses server HTML. Event replay and incremental hydration reduce lost clicks and work.
- Route-level render modes mix server, client and prerendered pages in one app.
- Browser-only code belongs in `afterNextRender`.
Common mistakes
- Referring to `@nguniversal` packages for new projects.
- Using SSR for pages that never change, where prerendering is cheaper.
- Reading `window` or `localStorage` during server rendering.
Follow-ups
- When would you prerender and when use SSR?
- What does event replay solve?
- How does `TransferState` avoid duplicate HTTP calls?
Tips
- Tell the story in four steps: Universal, hydration, CLI integration, render modes.
- Match render mode to page type.
- Mention the browser-only rule.
Evaluation rubric
- Gives a correct short history.
- Describes the modern setup and its parts.
- Chooses render modes sensibly.