Model Angular @defer blocks: triggers, prefetch, placeholder minimum and loading after and minimum

hardAbout 60 minutesUpdated CodingProangulardeferlazy-loadingcode-splittingperformancestate-machinetimers
Not solved

Share this question

Problem

Angular 17's @defer block splits a part of a template into its own chunk and loads it only when a trigger fires. Its sub-blocks control what the user sees meanwhile: @placeholder (minimum 500ms), @loading (after 100ms; minimum 1s) and @error. The timing rules exist to stop flicker, and they are easy to get subtly wrong. Build a model of one @defer block that follows Angular's rules.

const block = createDeferBlock({
  env,
  loadDependencies: () => import("./chart.js"),
  on: [{ type: "interaction" }],
  prefetch: [{ type: "idle" }],
  placeholder: { minimum: 500 },
  loading: { after: 100, minimum: 1000 },
});
// t=0 placeholder. Idle: the chunk starts loading. Click: if it already loaded, the chart shows at once
// (after the placeholder's 500 ms); otherwise loading may appear after 100 ms and then stays at least 1 s.

Ref. UR-1456 · © UIRound · uiround.com/questions/model-angular-defer-blocks-triggers-prefetch-placeholder-minimum-and-loading-after-and-minimum

Stuck? Take a hint

Try it in the editor

Run your code as often as you like. Submitting it to the full test suite is part of Pro.

Private, and saved in this browser as you type. All your notes are on My lists.

Every question and answer7 days, one payment