The Future of the Web
Join the DZone community and get the full member experience.Join For Free
i know, i know. the title sounds like seo-link-bait, i apologize. i want to talk about something that i'm fairly excited about, and i hope it excites you as well.
i've made it my mission over the past few years to focus my energy in this direction. anyone who reads this blog or listens to me give presentations knows this. developing for the web can still be pretty darn frustrating, but at least the tools, and the environment, are growing in leaps and bounds. there's some growing pains here, but my god, there's growth .
that is why i'm so excited to be hearing more and more about web components . web components refer to a few different technologies (that i'll list in a moment). but in general, they represent an incredible change in the web. to me, they truly are "web 2.0." for the first time you'll be able to define new building blocks (tags, behavior, design) by following web standards. you'll be able to extend the web. that is awesome.
so what are web components? in general, they describe the following technologies/specs:
the template feature will provide native support for this. you will be able to use a template tag within your html document. the content in the tag is not executed until you actually clone the template and add it to the dom yourself. so any images or script blocks won't be loaded until necessary.
to be clear, this isn't the exact same as something like handlebars.js . you don't get token replacement. but it is native to the browser itself which means less additional code.
you can read more about the spec here: https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html
shadow dom is - for me - the hardest concept to get my head around. i probably will not do a great job describing it, but in essence, it is a way to create a "black box" style system for content. let me give you an example. imagine you are writing some html that is meant to be consumed by someone else. your html is just a h1 tag and a paragraph. you want to style this content, but in order to do so, you have to ensure your css does not conflict with anything in the parent document. an iframe can solve this, but iframes create other challenges as well. with the shadow dom, you can essentially say, "this css will apply to this block only. period. nothing will leak out or in."
again - i'm not the best person to speak on this. you can read more about it at the spec ( https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html ) or check out the excellent html5 rocks article on the topic.
if you have ever used something like jquery ui's tabs to add tabs to your site, web components will allow you to do it all via web standards.
the final piece of the puzzle is html imports. essentially, once you've defined a custom element, applied some layout to it via the shadow dom and custom behavior, you can then create a reusable template that can be shared with others. in the same way you import a style sheet, the link tag will allow you to import custom elements. for example, x-tab or x-cowbell.
you can find the spec for this here: https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/imports/index.html
so what, i can't use it now!
i bet you're asking, how well is this stuff supported? right now support is pretty limited. in fact, custom elements aren't supported at all yet. the features that do work now are limited to chrome and firefox nightly. the specs are still in development. keep in mind though that a majority of our major browsers now are moving to a continuous update cycle. if you are still of the mindset that you don't need to care or pay attention to web standards then you are failing in your job as a web developer.
want to know more? there is an awesome, and short, video by eric bidelman of google that you can watch on this topic. i've embedded it below. you can also find his slide deck here: http://www.webcomponentsshift.com/ . do note though that you are supposed to click the right arrow to start the presentation. the initial gray screen confused me a bit and i assumed something had broken.
Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Top 10 Pillars of Zero Trust Networks
Java Concurrency: Condition
Authorization: Get It Done Right, Get It Done Early
Mastering Go-Templates in Ansible With Jinja2