Server-Side Rendering (SSR) in Angular improves performance, SEO, and faster page loads. With Angular 19, route-level render modes allow fine-tuned control over rendering. This guide explains how to optimize SSR using "full", "shell", and "no-ssr" render modes.
ng new my-angular-ssr-app --ssr
cd my-angular-ssr-app
Add Angular Universal if upgrading an existing project:
ng add @angular/platform-server
Update angular.json
to enable SSR:
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/my-angular-ssr-app-server",
"main": "src/main.server.ts"
}
}
app.config.ts
and enable SSR modes:import { ApplicationConfig } from '@angular/core';
import { provideRouter, withComponentInputBinding } from '@angular/router';
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(
[
{ path: '', component: HomeComponent, data: { renderMode: 'full' } },
{ path: 'dashboard', component: DashboardComponent, data: { renderMode: 'shell' } },
{ path: 'profile', component: ProfileComponent, data: { renderMode: 'no-ssr' } }
],
withComponentInputBinding()
)
]
};
"full"
: The page fully renders on the server (best for SEO)."shell"
: The initial UI loads on the server, but data loads on the client."no-ssr"
: The page loads only on the client (for real-time dashboards).const routes: Routes = [
{ path: '', loadComponent: () => import('./home/home.component').then(m => m.HomeComponent), data: { renderMode: 'full' } }
];
const routes: Routes = [
{ path: '', loadComponent: () => import('./home/home.component').then(m => m.HomeComponent), data: { renderMode: 'full' } }
];
Enable TransferState API to cache API responses between SSR and client:
import { TransferState, makeStateKey } from '@angular/platform-browser';
const DATA_KEY = makeStateKey('data');
this.http.get('/api/data').subscribe(data => {
this.state.set(DATA_KEY, data);
});
Reduce Unnecessary Rendering by deferring non-critical components:
@Component({
selector: 'app-dashboard',
template: `<ng-container *ngIf="isBrowser"> <app-heavy-component></app-heavy-component> </ng-container>`
})
npm run build:ssr
npm run serve:ssr
Route-level render modes in Angular 19 provide better performance control for SSR applications. By leveraging "full", "shell", and "no-ssr" modes, you can improve SEO, optimize initial load times, and balance rendering performance. Fine-tune SSR for different pages to create a faster, scalable web application. 🚀