Hacker News new | ask | show | jobs
by sslnx 3888 days ago
I have always been skeptical about Shadow DOM. It tries to solve different problems under one solution.

Say you want a static page without scripts but with CSS encapsulation. You cannot achieve that. Instead you have to use Shadow DOM and get it in package with other unneeded things.

CSS encapsulation could be solved with special attribute, new HTML tag or even with new CSS rule, and it would have been more flexible than Shadow DOM is.

1 comments

You're looking for "<style scoped>", which is in Firefox, used to be in Chrome, but was eventually removed in favor of Shadow DOM.

http://html5doctor.com/the-scoped-attribute/

http://caniuse.com/#feat=style-scoped

https://groups.google.com/a/chromium.org/forum/#!searchin/bl...

I think the main reason webcomponents won out over scoped styles is because usually once you need to scope your styles, you find you also need to scope your querySelector calls, and your DOM traversals, and your IDs....and pretty soon you have shadow DOM. It's unlikely that you need style namespacing if you're just a single dev working on a static page, and it's unlikely that you won't need JS & DOM scoping if your product grows beyond that.