Question presented to candidate:
"We wrapped our charting component in @defer, but the bundle analyser still shows the chart library in main.js. Explain how Angular decides what goes into a deferred chunk, and how prefetching changes when that chunk is downloaded."
What a strong answer should cover:
- The compiler generates a dependency function per
@deferblock that returns dynamicimport()s, and removes the matching static imports. - Dependency isolation rules: standalone dependencies only; not referenced eagerly elsewhere in the same file (outside the block, queries, class fields). Breaking the rule silently keeps them eager.
- Transitive dependencies: whatever the deferred component imports goes with it.
- Prefetch triggers (
prefetch on idle | viewport | interaction | hover | immediate | timer(...),prefetch when) download code before the render trigger fires. - How to verify: lazy chunk in
ng buildoutput, or the compiled_DepsFn.
Clarifying questions expected:
- "Is the chart component referenced anywhere else, for example by a query or a type used at runtime?"
- "Do we know when users usually need the chart, to choose a prefetch trigger?"
Code / implementation expected: Yes — a @defer block with separate on and prefetch triggers, and a look at the compiled output.