1

I have created a module in Angular (CustomCoreModule), which has grown over a period of time, causing performance issues and making the app non modular and un-maintainable.

I decided to create small modules and import them wherever needed instead of loading one big module (which decreases the bundle size).

If I created a module 'A', which eventually gets used in two lazy loaded modules, does Angular optimize the module twice for two different lazy loaded modules, when they are loaded or, will Angular try and load the module 'A' again for each module.

We are using Angular 8, with typescript. Also, will Angular 9 bring any benefit regarding this issue.

1 Answer 1

3

from Angular NgModule FAQ:

What if I import the same module twice?

That's not a problem. When three modules all import Module 'A', Angular evaluates Module 'A' once, the first time it encounters it, and doesn't do so again.

That's true at whatever level A appears in a hierarchy of imported NgModules. When Module 'B' imports Module 'A', Module 'C' imports 'B', and Module 'D' imports [C, B, A], then 'D' triggers the evaluation of 'C', which triggers the evaluation of 'B', which evaluates 'A'. When Angular gets to the 'B' and 'A' in 'D', they're already cached and ready to go.

Angular doesn't like NgModules with circular references, so don't let Module 'A' import Module 'B', which imports Module 'A'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.