Does performance overhead of creating an Angular 4+ component overcome the reusability advantage in case of one-element templates?
Does performance overhead of creating an Angular 4+ component overcome the reusability advantage in case of one-element templates?
Say you are an architect of a medium (and increasing) Angular 4+ application, and you are to decide the general approach for cases like:
- there is a limited piece of template
<a class="styled-anchor" target="_blank">Document</a>
- which you know will be used in several places in the application components.
Would you incline on creating a component (to avoid repeating the hard-coded class attribute, for instance) or rather prefer not to (given eventual performance/run/build cost the entire component wire-up brings)?
2 Answers
2
This question is not suited for StackOverflow as it is primarily opinion based.
I want to give a try anyway.
I think there are two reasons to create a component:
I think that creating a component for this would complicate the structure of the project. About the performance, of course there is an overhead, though it's not that big nor noticeable unless you generate hundreds of components at a time.
Is there any other place you would recommend starting such opinion prone threads?
– Michael
Aug 22 at 19:50
In a perspecitive of consistency, reusability and level of knoledge needed for someone new in the team (like medium one)...
If want to be more concise you have to create elements for almost every aspect of the view and reuse it a lot.
If you have to create a global class for a single element only you can end up with an app with no pattern in the views as remembreing names of classes are very triky and hard so I prefer to use components.
About build costs, if you reuse a lot you do not have to build it many times so you have a smaller bundle.
Going with a component is what I would tend to go with myself, because indeed that class gets redundantly hardcoded everywhere. Now I was just wondering what other people have experienced with, and if we do have an idea of what performance cost such small components add up to.
– Michael
Aug 22 at 19:53
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Any idea of how to "jsperf" this overhead?
– Michael
Aug 22 at 19:49