Thursday, September 25, 2014

Web Components 101

I recently watched Eric Bidelman's talk from Google I/O 2013 on Web Components.  This talk was on the Future of the web platform. This talk reminds me of Angular methodology where you are adding custom tags to HTML.

4 main areas (Shadow DOM gives encapsulation, templates or chunk of markup that later you can stamp out your elements, custom tags, html imports that can be reused via CDN URLs):











HTML templates:
Template out your markup 
Put dom in it
Parsed not rendered - won't run until you stamp it out, same for media
Hidden from document, cant traverse into,  its in its own context

Content property - document fragment , clone it, stamp it out, see whats in it

Example:


Clone it is what stamps it out (here it runs script when that happens):











New spec for html templates  : chrome supports it.




Shadow dom (Secret markup in elements):
markup encapsulation, DOM encapsulation, css style boundary protection, no bleeding in, style boundaries, exposes to developers mechanics browser vendors use to create their html elements

iframe has it but bloated, hard to use  (extra network requests needed, multiple rendering contexts)











Dom nodes can host hidden dom

hidden dom  can't be accessed by outside  javscript


Show shadow dom in web tools under wrench:







Hidden document fragment

Using markup to control it

Browser vendors been holding out
















Filled in markup

Shadow dom gets rendered


Style things

This time add styling make it red











@host

Host element provide default styles




















Custom elements (require hyphen)

Ability to define new elements

Plunkr example 





















































Using js html.prototype 

























































Html imports
































No comments:

Post a Comment