0

Let's say we have a big NgModule the SharedModule, which exports a lot of components which are needed in multiple components. By importing the SharedModule into a feature module there is often an overhead because all the shared components get imported and not just those which are necessary. Does splitting the SharedModule decrease the build-/compilation time? Are there any advantages to split it into smaller modules besides maybe better readable code?

Thanks a lot for your help!

sevic
  • 879
  • 11
  • 36

2 Answers2

2

From the official site angular.io:

The root module is all you need in a simple application with a few components. As the app grows, you refactor the root module into feature modules that represent collections of related functionality. You then import these modules into the root module.

and

Delineating areas of your app helps with collaboration between developers and teams, separating directives, and managing the size of the root module. A feature module is an organizational best practice, as opposed to a concept of the core Angular API.

There is nothing about decrease the build-/compilation time, so I think it makes sense

For large apps with lots of routes, consider lazy loading—a design pattern that loads NgModules as needed.

1

You can implement lazy loading that will reduced your app loading time Splitting functionality into modules will reduce app loading time you can implement lazy loading, you app will load on client side on demand like you have 5 modules, user wants to use module no 5 then this only module will load on client. other 4 module will not be loaded. browser first download your app on client side then extracted.your 5 module size is 5MB then after lazy loading your app size will be in different chunk. module size will according to functionality.

i am not sure about compile time reduce after modular approach. but your app loading time will definitely reduced, that things matter ,

your code will be well managed and readable. will be according to angular best practice

modular approach will decrease the complexity of code

Big module is not good approach. if you are working on big app Sooner or later you have to move your app into modular,otherwise maintenance or app loading time will not easy to tackle

Shahid Islam
  • 559
  • 3
  • 7