←back to thread

217 points palmfacehn | 1 comments | | HN request time: 0.218s | source
Show context
jjcm ◴[] No.45108239[source]
Templates are solid and are slightly more performant than including your html-in-js for webcomponents, but that said I really wish there was some sort of web component file format that incorporated:

- The HTML

- The JS

- The CSS

In some sort of a structured way that's easy to load and distribute as a library. I don't like that to use webcomponents the right way, you have to load the logic from an import and then inline the html aspects of it.

replies(3): >>45108412 #>>45108881 #>>45111534 #
marcosdumay ◴[] No.45108881[source]
Well, turns out you can just add style tags to the template, and they will be scoped there. It's the only way to get local CSS rules.

You can also add script tags wherever you want. They will execute when added to the DOM, but they won't be scoped.

replies(1): >>45109082 #
1. spankalee ◴[] No.45109082[source]
Styles aren't scoped to templates.

You might be thinking of shadow DOM: if you clone your template into a ShadowRoot, then any included styles will be scoped to that ShadowRoot.