Question presented to candidate: "Our initial bundle budget is tight, so every feature is lazy. Product wants the dashboard to open instantly, reports to be ready a few seconds after start-up, and settings only if the user shows interest. Design a custom preloading strategy for that, and explain what it does and does not do to the initial bundle."
What a strong answer should cover:
- Lazy routes are what shrink the initial bundle; preloading only changes when lazy chunks download, never what is in the initial chunk (it adds a little router code).
- A custom strategy is an
@Injectableclass implementingPreloadingStrategy.preload(route, load), registered withwithPreloading(MyStrategy), typically driven byroute.dataflags. - Patterns: eager (
return load()), delayed (timer(ms).pipe(mergeMap(load))), on intent (hover or viewport, via a shared service), skip (return EMPTY) for admin or rarely used routes. - The router runs one preload pass per
NavigationEndin sequence, so a strategy that waits indefinitely (for a hover that never comes) blocks later passes; fire-and-forget and returnEMPTYinstead. - Verify with
ng build: the lazy chunk table, the initial total, and the Network panel in a real browser.
Clarifying questions expected:
- "What is the bundle budget, and is it measured raw or compressed?"
- "Do we need to respect data-saver or slow connections?"
Code / implementation expected: Yes β a strategy reading data.preload with eager, idle-delay and hover modes, plus a log of when each loader runs.