#Standalone vs Module. What's your opinion?

1 messages · Page 1 of 1 (latest)

stray flame
#

Hi

I'm working with a team to migrate a whole application (~50.000 lines of code) to the newest version of Angular (from 11 to 16). Me and my team doesn't understand the advantage and disadvantage on using standalone components...
Some think it's better because the javascript files are lighter, but others say it generates more network calls. In the same way, some think it creates duplication at provider/import level.

Any thoughts / opinions about that ?

plucky sentinel
#

To my knowledge there is no real difference in the JS output. The real difference is with how developers work with the code.

There's no real advantage in migrating old components to standalone. For new components, you might consider creating them as standalone, but you have to trust your teammates to manage imports properly in every single component rather than just importing a SharedModule. Frankly: I don't trust the army of offshore junior devs I work with, so I'll be sticking with modules.

bleak narwhal
#

Technically, if properly written, 1 component per module will produce the same result as standalone components, it's more syntactic sugar really.

Lazily loading routes is most definitely a benefit (in regards to your comment on network calls), the more network calls the better because it means initial load times are faster if the route they're loading does not depend on components not needed until later in the app.

If you have 1 app.module.ts that loads in all of your components, lazily loading routes will provide almost zero advantage.

As SpaceChimp pointed out, its more of a workflow optimization really I think. Your component imports are tied directly to the component, there is no chance of it's imports floating in some arbitrary other module; thus, you'll get more optimized code.

mortal breach
stray flame
#

Thanks you three WumpsHeartyLove
We're going to migrate some of our modules to stand-alone components, but not all for the time being, as we need to compare performance. If I don't forget, I will come back here and share full performance analysis 👍

chrome acorn