Menu

1 / 7

Angular’s New injectAsync() API Explained

DEV Community·Brian Treese·6 months ago
#iWu2yAig
Reading 0:00
15s threshold

A ngular v22 just made lazy-loading services much simpler. In this post, we'll explore how to leverage the new injectAsync() API to reduce your main bundle size and replace awkward lazy-loading workarounds. We’ll compare the older manual lazy-loading approach with Angular v22’s new injectAsync() API and see why the new pattern feels simpler and easier to reason about.

The Problem: Libraries Loading Too Early

When building Angular applications, it's common to include third-party libraries for various functionalities.

However, if these libraries are not loaded efficiently, they can increase your initial bundle size, leading to slower application startup times.

In our demo application , we're using highlight.js and Marked for markdown processing and syntax highlighting.

In this case, the post-editor component itself is needed immediately, but the markdown-processing dependency isn’t.

Even though the feature might not be immediately needed by the user, these libraries are loaded upfront, contributing to a…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.