{"id":1752,"date":"2023-11-10T05:00:00","date_gmt":"2023-11-10T13:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1752"},"modified":"2026-03-12T01:49:17","modified_gmt":"2026-03-12T08:49:17","slug":"angular-17-trigger-options-for-defer","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/angular-17-trigger-options-for-defer\/","title":{"rendered":"Trigger options for @defer"},"content":{"rendered":"\n<p>We introduced the new <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/angular-17-lazy-loading-with-defer\/\" target=\"_blank\" rel=\"noopener\" title=\"\">@defer block<\/a> to lazy-load components on the screen. We saw that @defer includes several config options to display errors, placeholder, and loading templates.<\/p>\n\n\n\n<p>Today, let&#8217;s focus on the possible triggers for such lazy loading.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">idle<\/h2>\n\n\n\n<p>This is the default option. Will load the contents of that block once the browser is in an idle state:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"315\" height=\"98\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-15.png\" alt=\"\" class=\"wp-image-1753\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-15.png 315w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-15-300x93.png 300w\" sizes=\"auto, (max-width: 315px) 100vw, 315px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">viewport<\/h2>\n\n\n\n<p>Triggers the deferred block when its content enters the viewport. For instance, that would be when the user scrolls down, and the block becomes &#8220;visible.&#8221; Note that this option requires a placeholder (used to detect when the element comes into the viewport):<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"317\" height=\"183\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-16.png\" alt=\"\" class=\"wp-image-1754\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-16.png 317w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-16-300x173.png 300w\" sizes=\"auto, (max-width: 317px) 100vw, 317px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>Another interesting option is to load the deferred block when another specified element makes it into the viewport using a <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/template-reference-variables\/\" target=\"_blank\" rel=\"noopener\" title=\"\">template reference variable<\/a>. That option does not require a placeholder:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"407\" height=\"150\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-17.png\" alt=\"\" class=\"wp-image-1755\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-17.png 407w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-17-300x111.png 300w\" sizes=\"auto, (max-width: 407px) 100vw, 407px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">interaction<\/h2>\n\n\n\n<p>Waits for the user to <a href=\"https:\/\/angular.dev\/guide\/defer#on-interaction\" target=\"_blank\" rel=\"noopener\" title=\"\">interact with the placeholder<\/a> to load the deferred block. Even better, this trigger can  be combined with another element so you can lazy-load a component on a button click, for instance:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"438\" height=\"162\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-18.png\" alt=\"\" class=\"wp-image-1756\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-18.png 438w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-18-300x111.png 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>The above code can be <a href=\"https:\/\/stackblitz.com\/edit\/at-defer-trigger?file=src%2Fmain.ts\" target=\"_blank\" rel=\"noopener\" title=\"\">tested on Stackblitz here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">hover<\/h2>\n\n\n\n<p>Similar to the two previous examples. Waits for the user to hover over the placeholder or a specified element:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"338\" height=\"165\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-19.png\" alt=\"\" class=\"wp-image-1758\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-19.png 338w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-19-300x146.png 300w\" sizes=\"auto, (max-width: 338px) 100vw, 338px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">immediate and timer<\/h2>\n\n\n\n<p><code><a href=\"https:\/\/angular.dev\/guide\/defer#on-immediate\" target=\"_blank\" rel=\"noopener\" title=\"\">immediate<\/a><\/code> triggers the deferred block immediately as soon as Angular has finished rendering. <a href=\"https:\/\/angular.dev\/guide\/defer#on-timer\" target=\"_blank\" rel=\"noopener\" title=\"\">Timer<\/a> waits for a specified delay:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"597\" height=\"99\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-20.png\" alt=\"\" class=\"wp-image-1759\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-20.png 597w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/11\/image-20-300x50.png 300w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>You can see most of these different examples on Stackblitz here. There are a few more options for  <code>@defer<\/code> that I&#8217;ll cover later to keep this newsletter short and readable. It&#8217;s incredible what such a small API can do!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We introduced the new @defer block to lazy-load components on the screen. We saw that @defer includes several config options to display errors, placeholder, and loading templates. Today, let&#8217;s focus on the possible triggers for such lazy loading. idle This is the default option. Will load the contents of that block once the browser is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,21,20],"tags":[],"class_list":["post-1752","post","type-post","status-publish","format-standard","hentry","category-angular","category-architecture","category-performance"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=1752"}],"version-history":[{"count":4,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1752\/revisions"}],"predecessor-version":[{"id":2390,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1752\/revisions\/2390"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}