I'm wondering what's the best strategy between
- a shared module that contains all the reusable code
- individual reusable codes that are referenced when needed
I suppose that the case against putting all the reusable codes in a shared module is that it will be huge and will slow down the loading of the application because not every module need all the code in the share module.
Both GalleryModule
and ProfileModule
import CardModule
. They are both lazy loaded as well.
@NgModule({
declarations: [...],
imports: [
...,
CardModule,
...
]
})
export class GalleryModule { }
@NgModule({
declarations: [...],
imports: [
...,
CardModule,
...
]
})
export class ProfileModule { }
Let's say the user visits the gallery page. The galleryModule will be loaded along with its dependency, i.e. the CardModule. Let's say, after that, the user decides to go to the profile page, which will result in the ProfileModule being loaded.
Will the CardModule be loaded for the second time or will Angular just reuse the CardModule that was loaded along with GallelryModule?
Edit
It seems like someone else asked the same question here. However, it doesn't seem like anybody responded clearly to the question.
Thanks for helping.