ADVANCED ANGULAR • LESSON 17 OF 23

Deferrable Views with @defer

What you will learn

Load expensive UI only when the user or viewport needs it.

  • @defer moves eligible standalone dependencies into a separate JavaScript chunk. The initial route can become smaller and interactive sooner.
  • Choose a trigger that matches user intent: on viewport, on interaction, on idle, or when a condition becomes true. Prefetch can begin before display.
  • @placeholder is shown before loading, @loading during the import, and @error when loading fails. Reserve space to prevent layout movement.
  • Do not defer content required to understand or operate the page. Measure bundle and interaction changes instead of applying @defer everywhere.

How it works

1Initial route renders
2Trigger becomes true
3Chunk downloads
4Deferred view replaces placeholder

Expected result

The summary renders immediately. The chart code loads as its reserved area approaches the viewport.

Common mistakes

Do not defer the primary heading or first task. Do not omit an error state. Avoid a tiny placeholder that causes the page to jump when real content arrives.

Read the official Angular guide →