---
title: "Angular SSR and Hydration: Fast First Loads and SEO with @angular/ssr"
description: "A guide to Angular SSR and hydration: setting up @angular/ssr, provideClientHydration, event replay, incremental hydration, per-route render modes and fixing NG0500 errors."
url: https://sanderyaz.com/en/blog/angular-ssr-hydration-guide/
author: Sander Yazıcıoğlu
date: 2026-12-03
updated: 2026-12-03
lang: en
tags: ["Angular","SSR","Performance","SEO"]
---

# Angular SSR and Hydration: Fast First Loads and SEO with @angular/ssr

Moving projects that started on Angular 7 up to 20, server-side rendering was one of the areas that changed the most. Back then Angular Universal came as separate packages with its own configuration, and the browser threw away the server-rendered HTML and redrew the page from scratch. Users saw a full page first, then a short flicker. With `@angular/ssr` and hydration the picture today is very different. In this post I explain how I set up SSR in modern Angular and the problems that come up most often.

## Why SSR still matters

In an Angular app rendered entirely on the client, the first HTML is almost empty. Content only appears after JavaScript downloads and runs. Two consequences:

- **LCP is delayed:** especially on mid-range phones, the main content arrives seconds later.
- **Non-browser readers struggle:** Google can render JavaScript but queues it; social previews and many AI crawlers do not run it at all.

That is why SSR or prerendering still matters for corporate sites and content-heavy pages.

## Setup

For an existing project:

```bash
ng add @angular/ssr
```

This adds the server entry point, an Express-based `server.ts` and `app.config.server.ts`. For a new project, `ng new --ssr` does the same. If you are moving from Universal, remove the `@nguniversal/*` packages and upgrade versions step by step; the order is covered in the [Angular upgrade guide](/en/blog/angular-upgrade-guide/).

## Hydration: taking over the HTML instead of discarding it

Hydration, stable since Angular 17, lets the browser take over the server-rendered DOM instead of redrawing it:

```ts
// app.config.ts
import { provideClientHydration, withEventReplay } from '@angular/platform-browser';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes),
    provideHttpClient(withFetch()),
    provideClientHydration(withEventReplay()),
  ],
};
```

- **No more flicker:** the DOM stays in place and CLS drops.
- **`withEventReplay()`:** if the user clicks a button before JavaScript has loaded, the event is recorded and replayed once the app is ready. It became stable in Angular 19.
- **HTTP transfer cache:** `GET` requests made on the server are embedded in the page, so the browser does not repeat them. By default, requests carrying an authorization header are not cached.

## Incremental hydration

A long page does not need to be hydrated all at once. With incremental hydration, introduced in Angular 19, `@defer` blocks are rendered on the server but only come alive in the browser when needed:

```ts
provideClientHydration(withEventReplay(), withIncrementalHydration())
```

```html
@defer (hydrate on viewport) {
  <app-testimonials />
} @placeholder {
  <div class="h-64"></div>
}
```

Until the user scrolls to the testimonials, that component's JavaScript is not even downloaded. Ideal for heavy footers, maps and comment sections.

## Per-route render modes

Not every page needs the same strategy. `app.routes.server.ts` lets you choose per route:

```ts
import { RenderMode, ServerRoute } from '@angular/ssr';

export const serverRoutes: ServerRoute[] = [
  { path: '', renderMode: RenderMode.Prerender },
  { path: 'blog/:slug', renderMode: RenderMode.Prerender,
    getPrerenderParams: async () => (await listSlugs()).map((slug) => ({ slug })) },
  { path: 'panel/**', renderMode: RenderMode.Client },
  { path: '**', renderMode: RenderMode.Server },
];
```

| Mode | When |
|---|---|
| `Prerender` | Pages whose content is known at build time: home, services, blog |
| `Server` | Pages that change per request but must be indexed |
| `Client` | Logged-in dashboards, where SSR adds nothing |

## Common errors

**`window is not defined`:** there are no browser APIs on the server. Make access to `localStorage`, `window` and `document` browser-only:

```ts
constructor() {
  afterNextRender(() => {
    this.theme.set(localStorage.getItem('theme') ?? 'dark');
  });
}
```

`afterNextRender` only runs in the browser and reads better than an `isPlatformBrowser` check.

**NG0500 hydration mismatch:** happens when the server and the browser produce different DOM. The usual causes: third-party libraries that use `innerHTML` or manipulate the DOM directly, invalid HTML (a `<div>` inside a `<p>`, for example), and `Date.now()` or random values that differ between server and browser.

**The escape hatch:** the `ngSkipHydration` attribute excludes a component you cannot fix from hydration. It is a temporary workaround, not a permanent one.

**Timers:** a `setInterval` running on the server can delay the end of rendering. Move periodic work to the browser.

## Measuring it

Core Web Vitals tell you whether SSR is paying off. Compare LCP and CLS before and after hydration using field data from real users. For the measurement approach see the [Core Web Vitals post](/en/blog/react-core-web-vitals-lcp/); the examples are React, but the metrics are the same.

## Conclusion

In modern Angular, SSR is no longer a separate project but one `ng add` command and a few providers. Hydration ends the flicker, event replay rescues early clicks, and incremental hydration with per-route modes brings the JavaScript cost down to where it is really needed. The real work is isolating browser-only code and making sure server and browser produce the same DOM. If your app still uses NgModules, the [standalone migration guide](/en/blog/angular-standalone-migration/) is a good first step.

---

About the author: [Sander Yazıcıoğlu](https://sanderyaz.com/en/about/). Sander Yazıcıoğlu is a Senior Full-Stack Developer in Istanbul. At LiveTesting he builds the backend, frontend, realtime systems and Appium automation of a real-device testing platform; before that he built enterprise Angular apps at Testinium and Loadium.
