2
votes

In my electronic component, I import my shared.module(has featured-brand.component, product-list.components, etc) and also I import my shared modules in my other categories (video games, toys, etc). Some of the components in my shared.modules are not used when I import them. Will these unused components in my shared module slows down the my application? Thanks a lot in advance.

1
are they referenced in entryComponents? - Max Koretskyi

1 Answers

7
votes

The criteria "slow down" is difficult to quantify. To answer your question though, it's helpful to understand what declaring components in a module actually does:

An NgModule is a class decorated with @NgModule metadata. The metadata do the following:

  • Declare which components, directives, and pipes belong to the module.

Simply declaring your components there won't meaningfully affect performance. It just makes Angular aware of their existence, so they can be matched to your component selectors.

However, this comes with a huge caveat - if you're using Angular in production with a typical build process, the components that you declare on your modules are going to be bundled in your output JavaScript (they won't be removed by tree-shaking). Typically this is the correct behavior (as your component is still being used by some things). If you're lazy-loading, however, and performance is critical, you'll want to make sure that you aren't packing unnecessary components into your bundles.