Question presented to candidate: "We moved every feature behind lazy routes and the first load got faster, but now opening each section for the first time has a noticeable pause. What are preloading strategies in Angular, and which one would you pick?"
What a strong answer should cover:
- Preloading downloads lazy route code in the background after a navigation finishes, so a later navigation to that route needs no download.
- The built-in strategies:
NoPreloading(the default) andPreloadAllModules, enabled withprovideRouter(routes, withPreloading(...)). - A custom strategy is a class implementing
PreloadingStrategy.preload(route, load)that decides per route: callload()or returnEMPTY. - Preloading covers both
loadChildrenandloadComponent, runs afterNavigationEnd, and does not consultcanMatch(routes with the deprecatedcanLoadare skipped). - The trade-off: initial load stays small, but users pay bandwidth for screens they may never open; mobile and metered connections deserve care.
Clarifying questions expected:
- "Do most users visit most sections, or only one or two?"
- "Are there areas, like admin, that most users should never download?"
Code / implementation expected: Yes β withPreloading(PreloadAllModules) and a log showing when the loaders run compared with NoPreloading.