Lazy-loading with @defer

Lazy-loading with @defer

Master Angular lazy-loading with @defer and learn how to control triggers, placeholders, loading behaviour, and error states for standalone components.

Alain Chautard

Alain Chautard

March 17, 2026

Lazy-loading with @defer

Today, let’s cover how to fully customize lazy-loading with Angular using @defer.

What’s great about @defer is that it no longer relies on the Angular router. You can lazy-load any standalone component anywhere, anytime, and on your terms, as you can decide the trigger to load that component.

Let’s start with a basic example:

2Jhofus0QjKKqr4iUGf6GAsUj9rndZUlpWLhiV88.png

The above code will load the HelloComponent as soon as the browser is idle, which means it’s done loading everything else. While that is happening, we can decide to display a placeholder, and in my case, I decided that such a placeholder would be displayed for a minimum of 2 seconds no matter what. You can use seconds (s) or milliseconds (ms) as a time unit:

DoKFuqK6cD07U5qyjnb1EtLgNHD1wpEPK7hKJlRF.png

You can see the above code in action here on Stackblitz. Note that the Angular Language service was updated accordingly, so VS Code (Stackblitz is a web-based VS code), Webstorm, and other IDEs already know about the new @defer syntax and do proper highlighting of it!

We can also specify a loading template and an error template, all customizable with a minimum amount of time during which we would display those templates (example on Stackblitz here):

si8oUf3LwbKLFRbkRkxfoLwVCuMjb7kRoI6M09VO.png

I used “big” numbers to see the different states in my examples. Note that @loading supports an “after ” option only to show the loading template if loading takes more than a certain amount of time, so you don’t have to display anything if the component loads quickly. Both parameters are optional:

BXCtlaKDsR14hIDqVsOcSdVtvs0oEFVluup2kQ2d.png

These are the different new blocks available with @defer.

Next, you can look at the different trigger options.

This article originally appeared on Angular Training.

More certificates.dev articles

Get the latest news and updates on developer certifications. Content is updated regularly, so please make sure to bookmark this page or sign up to get the latest content directly in your inbox.

Looking for Certified Developers?

We can help you recruit Certified Developers for your organization or project. The team has helped many customers employ suitable resources from a pool of 100s of qualified Developers.

Let us help you get the resources you need.

Contact Us
Customer Testimonial for Hiring
like a breath of fresh air
Everett Owyoung
Everett Owyoung
Head of Talent for ThousandEyes
(a Cisco company)