Shadow Master: Shadow DOM
I have had many sleepless nights trying to deal with CSS
bleeds and clashing element id attributes. You have to expect this when you are
working on a code base that is accessible to a lot of developers especially in
an enterprise setting.
Good thing that I am not the only one encountering this
problem and the new w3c specification hopefully would address this problem. (http://www.w3.org/TR/shadow-dom/#dfn-functional-encapsulation)
The SHADOW DOM
As defined in the specification this addresses the
functional encapsulation of element in the DOM tree.
What does this mean? Well first you can now have chunks of
html elements with styling that will not affect the rest of the DOM tree. Why
would you want to have chunks of html elements? Of course to create widgets.
This is the reason why the Shadow DOM is an important part of building web
components.
Once you created a chunk of html (like a widget) you can now
re-use this widget all over the place without the fear of having it’s style
messing up the rest of your page and you might even want to provide that widget
to other developers to use, without them messing the styling of what they are
working on. The Shadow DOM is an essential specification to bring forth more
complicated and sophisticated web applications because it gives web
developers the tools to create complicated widgets that can be re-used with
little effort and integration issues.
Here is a great link on how you can use a template and use
the shadow DOM
Comments