WARNING 
this is a tech talk 
@yaviner
Building Blocks Web Components and the Future of HTML 
@yaviner 
aka cool stuff you should be thinking about
Introductions…briefly 
Rutgers Alum (’14, RBS) 
Some startups, hackathons 
UI Developer for iCIMS 
Likes geeky things, whiteboards 
@yaviner
Enough of that. 
@yaviner
We’re going to talk about web components. 
@yaviner
SOME WEB HISTORY 
Give me some context, bro 
@yaviner
@yaviner
The horror! 
Bloated HTML 
Difficult to read, maintain 
Wrong-semantic meaning (without even mentioning accessibility…) 
@yaviner
But it kind of made sense… at the time 
Finicky browsers 
Immature standards 
We needed predictable results 
@yaviner
SO WHAT DID WE 
DO ABOUT IT? 
“but I’ve never seen a table based design” – You, 2014 
@yaviner
<div> 
@yaviner
<span> 
@yaviner
CSS 
@yaviner
CSS3 
@yaviner
@yaviner
But that was like a decade of 
tables, what gives?
HTML’s authors envisioned an Internet of information, not an Internet 
of entertainment and interactivity. CSS wasn’t supported in most 
browsers until around version 5. 
@yaviner
We (developers, browsers) 
realized that content and 
presentation were meant to 
be separate. 
@yaviner
HTML is most appropriate 
as a declarative language 
@yaviner
HTML5 Introduced: 
<article> - A block of grouped, related information. 
<section> - Logical separation of groups of information. 
<video> - A video! This needs playback! 
@yaviner
If we commoditize this idea and apply it broadly, 
we can refer to these elements as components. 
@yaviner
What if I need to build an app? 
@yaviner
Current HTML for a Hangout 
(mmm…soupy) 
@yaviner
<div> is a limited-meaning tag. Without an ID, 
it’s nothing but a visual separator. 
@yaviner
What if we could write it like this? 
@@yyaavviinneerr
@yaviner
What if our HTML was just a series of 
components? 
@yaviner
The idea isn’t new. 
@yaviner
@yaviner
All built on the principles of web components. 
@yaviner
But frameworks bring costs, and so their plugins 
are not “free” like “<input type=“date”> is free. 
@yaviner
The most famous client side projects are 
fated to die. 
- Zeno Rocha 
@yaviner
Just as CSS heralded in the era of “Web 2.0”, these 
frameworks have been nudging us toward native 
web components for years. 
@yaviner
So what are web components? 
@yaviner
They empower us to natively define and 
extend HTML. 
@yaviner
And share it with others. 
@yaviner
HOW? 
@yaviner
Shadow DOM -> Encapsulation 
@yaviner
HTML Templates -> Inert, Re-usable DOM. 
@yaviner
Custom Elements -> Semantics, Extensions 
@yaviner
HTML Imports -> 
Import an entire component with one line 
@yaviner
All of this is regular DOM. 
@yaviner
SOME EXAMPLES 
@yaviner 
What you really wanted
<video is=“camera”> 
eduardolundgren.github.io/video-camera-element 
@yaviner
<table is=“datatable”> 
@yaviner
<youtube-video id=“dQw4w9WgXcQ”> 
@yaviner
<google-maps> 
eduardolundgren.github.io/google-maps-element 
@yaviner
<twitter-button> 
zenorocha.github.io/twitter-button 
@yaviner
I heard you like frameworks 
@yaviner 
No, I’m not including xzibit here
Polymer is an opinionated framework on top 
of Web Components. 
It’s backing muscle includes Google and others. 
@yaviner
X-Tags is another cool one 
The brains? Mozilla 
@yaviner
@yaviner
@yaviner
But the ultimate goal of these frameworks is 
to become redundant. 
@yaviner
The most famous client side projects are 
fated to die. 
- Zeno Rocha 
@yaviner
What about <insert-existing-JS-framework>? 
@yaviner
Angular and Ember will both support (and export!) 
native web components in their next iteration. 
@yaviner
Where can I learn more? 
@yaviner
Sites: 
webcomponents.org 
polymer-project.org 
x-tags.org 
customelements.io 
People: 
Eric Bidelman @ebidel 
Zeno Rocha @zenorocha 
@yaviner
GO FORTH AND BUILD 
@yaviner
Thank you! 
Questions? 
@yaviner

Web Components - Rutgers Tech Meetup Fall 2014

Editor's Notes

  • #6 ..But before we get started,
  • #7 Let’s take a trip in the wayback machine
  • #8 If you don’t, you can count yourself an enlightened modern developer. To the rest of you, I apologize for the flashbacks
  • #9 Nested tables on tables! You can roughly mark this era by the rise and fallof the <marquee> tag. And spacer gifs.
  • #10 But we don’t have to be proud of it.
  • #18 Our limited selection of semantic tags early on reflects this - h1? ul? . Eventually browsers added CSS support. But the HTML spec took a bit longer to add better semantic tags, so we used <div>, which assumed nothing about our content.
  • #19 But the fundamental distinction here was that:
  • #20 Let’s leave out, in HTML, the details of how our application should look or behave, and simple declare the logical components of the page. Ideally, both humans and machines can read this semantic code and understand their purpose without bothering themselves with the implementation details. So HTML5 gave us some new toys to start with:
  • #21 We simply declare the element’s purpose, and everything else will follow.
  • #23 What if my needs are more complex? What do I declare for my in-app sharing components? My chat module?
  • #25 <div> itself is not declarative of a component. It literally just stands for ‘division’. It’s the building block, but you don’t call a house a brick. We traded wrong-semantic code in our components for non-semantic code.
  • #28 What if our apps were beautiful, declarative code?
  • #31 When you grab a jQuery slideshow, an Angular table sorter, a Bootstrap pill navigation bar…this is based on the encapsulation and re-use of logical page elements.
  • #32 A new HTML5 feature!
  • #33 We didn’t stop using FLASH because it wasn’t useful. We stopped using FLASH because we figured a better way to do it natively.
  • #34 And we’ve embraced this.
  • #35 I’ve blabbed for a bit on this, but I haven’t given away the meaty bits.
  • #36 This actually leads to a sort of object-oriented HTML. But I’ll get to that.
  • #38 Besides classic programming fuel, of course. Warning, this is tech-ier than the rest.
  • #39 The ShadowDOM has been around for a while, actually. It’s what powers that cool <video> tag. It’s a DOM that your external scripts do not reach into or traverse. But the browser can. In fact, if you enable a flag in chrome you can inspect the <video> tag’s ShadowDOM and find… it’s made up of the same divs and spans that we use. JS events in the shadowDOM bubble up to their host, and in fact appear to come from their host. Everything inside the <video> tag is isolated from the rest of your page, and does not share its styles. Until Web Components, only the browser itself could access shadowDOM.
  • #40 Have you ever used Handlebars? EJS? Jade? You’re familiar with templating, but you’ve never seen it native. The <template> tag in HTML5 allows us to specify inert DOM which is read but not parsed until its called into action. They’re also responsible for the re-usability of web components. Used to their fullest extent, they also allow us to create full JS APIs for our elements.
  • #41 This is another chunk of the heart of web components. Of course, this allows us to define our own HTML tags, but libraries like polymer allow us to extend existing HTML elements.
  • #42 This is the heart of web component shareability. Instead of importing bootstrap css, js, jquery, just to use bootstrap tabs, we can import a single html file which defines the tag. We can share these more easily and reach wider audience.
  • #43 You get mutation observers, querySelector, event listeners, caching, interoperability with any and all frameworks. And first-class devtools support.
  • #44 Warning, this is tech-ier than the rest.
  • #45 This tag allows, in a single import and declaration, a video element which requests and displays a webcam feed.
  • #46 Tables have come a far way, but they’ve always been difficult to work with, even for what they were meant for. We could extend the table element to add an easy JS API to add rows or retrieve data. Who here has used jQuery just for the dataTables plugin?
  • #47 Self-explanatory. Simple. No iframes.
  • #48 Just supply a latitude and longitude and you’re good to go!
  • #49 No iframes!
  • #50 Warning, this is tech-ier than the rest.
  • #51 Polymer adds a lot of cool stuff like two way data binding and subtemplates
  • #56 This should all become standard, and the frameworks will fade away. Or, at least, stop focusing on custom element creation.
  • #57 Doesn’t Angular do custom elements itself? Well, I think we’d all prefer a standards method way of declaring elements. Especially when:
  • #58 Though they can interact with them as normal elements now anyway, since they’re just regular DOM.