HTML templates are nice and fast. The problem is HTML import has been deprecated. This means it makes the most sense to put web components each in their own .js file instead of .html files. However if one uses a .js file, then as far as I can tell, one can't use a precompiled template to attach at the shadow DOM, one has to use some fixed string that I imagine is parsed every time.
With .html web component one could do:
shadowRoot.appendChild(myTemplate.content.cloneNode(true));
However in a .js file you have to do something like:
something.innerHTML = `
<style>
...
/* lots of style */
</style>
<b>I'm in shadow dom!</b>
<!-- lots of html -->
<slot></slot>
`;
Is this not a bad idea because the text must be revaulated every time, whereas a template is evaulated once?
So what is the recommened way of embedding one's style and html in a .js file for a web component?
I am using vanilla JS, no frameworks.
<link>element that points to that stylesheet.