Alexander Thalhammer from Graz, Austria (est. 1983) • Angular Software Tree GmbH (est. 2019) • Web Dev for 25 years • Since 2017 Angular Dev • Since 2021 Angular Evangelist, Coach & Consultant • Member of the Angular Architects Hi, it's me à @LX_T
only works with standalone components • alternative to router-based Lazy Loading in Angular • to reduce initial load (size and time) à improve performance • without own route • very good DX compared to previous solutions with ViewContainerRef Deferrable Views with @defer (v17)
widgets that are used on multiple routes • lazy loading large 3rd-party dependencies (e.g., charts, tables, etc.) • forces CSR à combine with SSR for user-dependent content (e.g., price) • not suited for above-the-fold content (initially only placeholder is shown) Deferrable Views – Examples
on • immediate • idle (default) • viewport (like ngOptimizedImage) • hover (mouseover & focusin) • interaction (click & keydown) • timer(4200ms) (use case à demo) Deferrable Views – Trigger Details • when • boolean symbol or • Signal<boolean> or • function • both are one-way ticket • combination possible
with prefetch, the deferred JavaScript can be preloaded • similar to the PreloadingStrategy used in router-based lazy loading • this speeds up the loading process when the @defer trigger is activated Deferrable Views – Prefetch
be careful with nested @defer blocks • they should use different triggers • be cautious when @defer is triggered above-the-fold and during the initial load • no layout shifts should occur (poor UX) Deferrable Views – Best Practices
in combination with SSR, the @placeholder is rendered on the server • or nothing if no @placeholder is provided • only on the client the @defer blocks' main content is rendered • thereby enforcing client-side rendering • only with Incremental Hydration main content pre-rendered on the server Deferrable Views – Combination with SSR
based upon Hydration, @defer and Event Replay • enables even better intial load experience, because • less JavaScript is shipped à partial lazy loading of JS on demand • @defer blocks now can also be used above-the-fold, because • the main content (instead of @placeholder) is rendered on the server Incremental Hydration (v19)
same triggers like @defer • on (immediate, idle, viewport, hover, interaction) • when (boolean symbol, Signal<boolean> or function) • never (for static content without interactivity) Incremental Hydration – Trigger
improve you initial load with SSR SSG (prerender) static content @defer for components below-the-fold Incremental Hydration for above-the-fold try it & play with it!
angular.dev/guide/performance - official SSR docs • angular.dev/guide/incremental-hydration - official IH docs • youtube.com/watch?v=v5KTJGEYLsM – IH intro by Jessica Janiuk • angulararchitects.io/blog/complete-guide-for-server-side-rendering-ssr-in-angular/ • angulararchitects.io/training/angular-performance-optimization-workshop/ Ressources