Tech Interview RoomStudy guides

Angular

How do you make a large Angular application fast? SSR, hydration, defer and bundle size.

Advanced · 2 min read · Lesson 8 of 8 in Angular

Rendering and loading

  • SSR with @angular/ssr (ng add @angular/ssr) renders HTML on the server for fast first paint and SEO; prerendering (SSG) for static routes; per-route render modes (server, client, prerender) in recent versions.
  • Hydration (provideClientHydration()) reuses the server-rendered DOM instead of re-creating it; incremental hydration with @defer (hydrate on viewport) keeps parts dehydrated until needed; event replay captures clicks before hydration completes.
  • Lazy loading routes and @defer blocks for heavy components (charts, editors, maps).
  • Image optimisation with NgOptimizedImage (<img ngSrc>): sets priority for the LCP image, lazy-loads others, warns about missing sizes.

Runtime performance

  • OnPush everywhere and signals (or zoneless) to limit change detection.
  • @for with a proper track expression so lists are not re-created.
  • Virtual scrolling (cdk-virtual-scroll-viewport) for long lists.
  • Avoid functions in templates (use computed or pure pipes); run heavy work in Web Workers.

Bundle size

  • The esbuild-based application builder (default) with budgets in angular.json to fail builds that grow too much.
  • Analyse with ng build --stats-json and an analyser; remove unused dependencies; import only what you use (standalone components make tree shaking effective); avoid large polyfills.

Example

ts
// app.config.ts
export const appConfig: ApplicationConfig = {
  providers: [
    provideZonelessChangeDetection(),
    provideRouter(routes, withPreloading(PreloadAllModules)),
    provideClientHydration(withEventReplay(), withIncrementalHydration()),
    provideHttpClient(withFetch()),
  ],
};
html
<!-- product.page.html -->
<img ngSrc="/img/hero.avif" width="1200" height="600" priority alt="Product hero" />

@defer (on viewport; hydrate on interaction) {
  <app-reviews [productId]="id()" />
} @placeholder {
  <div class="skeleton" style="height: 320px"></div>
}

<cdk-virtual-scroll-viewport itemSize="48" style="height: 480px">
  <div *cdkVirtualFor="let row of rows; trackBy: trackById">{{ row.name }}</div>
</cdk-virtual-scroll-viewport>

Follow-up questions interviewers ask

Try answering each one before you open it.

How do you migrate an old NgModule-based app to modern Angular?

Upgrade one major version at a time with ng update, then run the official schematics: ng generate @angular/core:standalone (standalone components), @angular/core:control-flow (*ngIf/*ngFor to @if/@for), @angular/core:signal-input-migration and inject migration. Enable OnPush gradually, then consider zoneless once components no longer depend on Zone.js-triggered updates.