Angular Tutorial 0/55 lessons ~6 min read Lesson 43

    Angular @defer Deep Dive

    @defer lazy-loads template blocks when a trigger fires — idle, viewport, interaction, hover, timer, or a custom condition.

    Course progress0%
    Focus
    6 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    @defer lazy-loads template blocks when a trigger fires — idle, viewport, interaction, hover, timer, or a custom condition. Pair it with @placeholder, @loading, and @error for production UX. This lesson deepens the overview in the Control Flow lesson.

    Purpose of this lesson

    You will defer a heavy chart widget until it enters the viewport and prefetch on hover.

    Understanding the topic

    Triggers to know:

    • on idle — after browser idle (good default for below-the-fold).
    • on viewport — when the placeholder enters the viewport.
    • on interaction / on hover — user-driven.
    • on timer(2s) — delayed load.
    • when condition — boolean expression.
    • prefetch on ... — warm the bundle earlier than the render trigger.

    Informative example

    Viewport + prefetch:

    html
    @defer (on viewport; prefetch on hover) {
    <tlp-course-analytics [courseId]="courseId" />
    } @placeholder {
    <p>Analytics preview</p>
    } @loading (minimum 400ms) {
    <p>Loading analytics…</p>
    } @error {
    <p>Could not load analytics.</p>
    }

    Best practices

    • Keep placeholders layout-stable to limit CLS.
    • Prefetch on likely intent (hover) for primary CTAs.
    • Do not defer content required for SEO above the fold without SSR strategy.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    1 questions
    1AdvancedQuestionHow does @defer interact with hydration?+

    Answer

    Deferred blocks can skip or delay downloading client code. Incremental hydration builds on similar ideas — hydrate when the user needs the island. Coordinate defer triggers with hydration configuration so the server HTML and client behavior stay aligned.
    Ready to mark this lesson complete?Track your journey across the entire course.