If I understand it correctly, creating an instance of a web component can be summed up as creating a shadow root and copying the markup, e.g. from a template into it:
var Template = document.querySelector('#myTemplate');
var TemplateClone = document.importNode(Template.content,true);
TargetElement.appendChild(TemplateClone);
Of course, if the template contains css rules in a style-tag, those will be copied as well. Thus we can have scoped styles which belong to the internal markup of a web component.
Questions:
- Does it have any performance implications when I create tons of instances of the very same web component, as the style is just copied and not reused?
- Is there a way to share the style node across multiple instances of the same web component?