Angular Academy · Lesson

Deferred Loading with @defer

Lazy-load template sections with @defer.

Lesson 4 of 413 steps

Deferred Loading with @defer is a free Angular Academy lesson on CoddyKit. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, and your progress syncs across the web and the CoddyKit app. The Angular Academy course includes 4 lessons in total.

Deferred Loading with defer

The at-defer block lazily loads part of a template and its dependencies, improving initial load performance. The deferred content is split into a separate chunk.

Basic defer Syntax

Wrap content in an at-defer block. By default it loads when the browser is idle.

// @defer {
//   <app-heavy-chart></app-heavy-chart>
// }

Why Defer

Deferring heavy or below-the-fold components keeps the initial bundle small and the first paint fast. The component loads only when actually needed.

The placeholder Block

An at-placeholder block shows content before the deferred block is triggered.

// @defer {
//   <app-comments></app-comments>
// } @placeholder {
//   <p>Comments will load soon</p>
// }

The loading Block

An at-loading block shows while the deferred chunk is being fetched.

// @defer {
//   <app-comments></app-comments>
// } @loading {
//   <p>Loading comments...</p>
// }

The error Block

An at-error block renders if loading the deferred dependencies fails.

// @defer {
//   <app-comments></app-comments>
// } @error {
//   <p>Failed to load comments</p>
// }

Triggers

You control when loading starts with triggers in an on clause, such as on idle, on viewport, on interaction, on hover, or on timer.

// @defer (on viewport) {
//   <app-chart></app-chart>
// }

on viewport

The on viewport trigger loads the content when it scrolls into view, perfect for below-the-fold sections.

on interaction and on hover

on interaction loads when the user clicks or focuses the placeholder; on hover loads when the pointer hovers over it.

// @defer (on interaction) {
//   <app-editor></app-editor>
// } @placeholder {
//   <button>Open editor</button>
// }

The when Condition

You can also trigger on a boolean expression using when, loading once the expression becomes true.

// @defer (when shouldLoad()) {
//   <app-details></app-details>
// }

Prefetching

You can prefetch the deferred chunk separately from rendering, for example prefetch on idle, so it is ready before the render trigger fires.

// @defer (on viewport; prefetch on idle) {
//   <app-chart></app-chart>
// }

Quick Check: defer

Triggering deferred content.

Recap: Deferred Loading

You learned the at-defer block for lazy loading, with at-placeholder, at-loading, and at-error blocks, and triggers like on idle, on viewport, on interaction, on hover, on timer, and when, plus prefetching. You have completed the Built-in Control Flow course.

Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
38
Lessons
144

Frequently Asked Questions

Is the “Deferred Loading with @defer” lesson free?

Yes — any 3 lessons of the Angular Academy learning path, including “Deferred Loading with @defer”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Angular Academy course includes 4 lessons in total.

What will I learn in “Deferred Loading with @defer”?

Lazy-load template sections with @defer. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Angular Academy?

No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.

How long does the “Deferred Loading with @defer” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Angular Academy lesson?

Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Conditional Rendering with @if
  2. Looping with @for
  3. Switching with @switch
  4. Deferred Loading with @defer
← Back to Angular Academy