Hacker News new | ask | show | jobs
by jamiedumont 878 days ago
I'd like to like web components, but their reliance on JS to instantiate along with all the chaos of the shadow DOM keep them off the table for me. I think they are a great concept defeated by the implementation.
1 comments

google "html web components"
It's a nonsensical term for components with predefined markup and no Shadow DOM
So essentially what partials in a template or server-side include solve.

That's the only "build-like" part of my current website, but I'd much rather manage this beforehand and serve static HTML, or run a server-side process than use JS/HTML web components at runtime.

JS/HTML web components are the static HTML –

``` <marker-of-dynamic-behavior> {your standard static html} </marker-of-dynamic-behavior> ```

This is just a better way of doing DOM scripting, enhancing without waiting for Document Ready event, and having more freedom when to load the dynamic bits.

> This is just a better way of doing DOM scripting

Better than what?

> enhancing without waiting for Document Ready event

Instead you wait for `connectedCallback`

> and having more freedom when to load the dynamic bits.

You literally have no freedom over that. Web components are rendered the moment they are added to the page, and you have no control over that. So if something dynamic is happening in your `connectedCallback`, boom, our dynamic bits are loaded whether you want them or not.

better than centralized `$('.special-element').applyDynamicBehaviour()`

you control when the script is loaded right?

connectedCallback happens per component, not in a centralised manner – so you write the logic for what happens in a place where it happens

They still rely on JS to instantiate though unless I've misinterpreted?
the point of them is that you are providing full proper HTML and CSS so client-side stuff kicks in only when it can and needs to be kicked in.
> so client-side stuff kicks in only when it can and needs to be kicked in.

All web components are rendered eagerly, so it kicks in immediately the moment it appears on the page.

No, it appears on the page = HTML and CSS is parsed. When you load your scripts is up to you.