SlideShare a Scribd company logo
1 of 38
Download to read offline
Web Components - The Future is
Here
Gil Fink
CEO and Senior Consultant, sparXys
The Pyramid of Doom
About Me
• sparXys CEO and senior consultant
• ASP.NET/IIS Microsoft MVP in the last 7 years
• Pro Single Page Application Development (Apress)
co-author
• 4 Microsoft Official Courses (MOCs) co-author
• GDG Rashlatz and ng-conf Israel co-organizer
Agenda
• The problems we face
• Web Components APIs
o Templates
o Imports
o Shadow DOM
o Custom Elements
1. Undescriptive Markup
Markup Example
2. Poor Separation of
Concerns
You want HTML, CSS and
JavaScript to work together
You end up with a mess
The wiring gets in your way!
3. No Native Templates
• Store HTML in hidden DOM element and show it
• Use script tag as a template holder:
<script id=”myTemplate” type=”text/template”>
<div>
…
</div>
</script>
4. No Bundling
• You want to bundle a complex component
The component includes HTML, CSS and JavaScript
how would you do that?
o Use a server side wrapping mechanism?
Web Components to the
Rescue
• A set of standards designed to componentize the
web
• Some general goals:
Code Reuse Encapsulation
Separation of
Concerns
Composition Theming Expressive Semantic
The Web Components
Standards
•Reusable DOM fragmentsTemplates
•Load HTML declarativelyImports
•DOM encapsulationShadow DOM
•Create your own elements
Custom
Elements
Setting The Environment
• Browsers have only partial support for Web
Components
o So we use the webcomponents.js Polyfill for Web Components
• Download:
o https://github.com/webcomponents/webcomponentsjs/
o Or install using your favorite package manager (NPM, Bower, Nuget)
• Make sure the Polyfill script runs first
Demo
Setting the environment
Let’s Drill Down
Templates
• A new HTML element – template
o Can be used to instantiate document fragments
o Can wrap HTML, style tags and script tags
• No data binding support 
• To use a template you need to write some
JavaScript code
<template id=”myTemplate”>
<div>
…
</div>
</template>
Cloning a Template
• Select the template and extract its content
o Using its content property
• Use the importNode function to get the cloned
content
• Only when the clone is appended to the DOM
o The style and JavaScript are executed
o Resources such as images are fetched from the server
var template = document.querySelector(‘#myTemplate’);
var clone = document.importNode(template.content, true);
Templates
Demo
Imports
• Load additional HTML documents
o Without Ajax
• A new type of link tag
• Use the rel attribute with the import type:
<link rel=”import” href=”myImport.html”>
Imports and Bundling
• Enable to bundle a full component into one HTML
file
o The HTML can include scripts and styles
• The whole bundle can be retrieved in a single call
Imports and The DOM
• Importing a document doesn’t include it into the
DOM
o It will parse it in memory and load all the additional resources
• Use the import property of the link tag:
var content =
document.querySelector(‘link[rel=”import”]’).import;
Imports
Demo
Import Notes
• Scripts running inside the import can reference the
containing document
o By calling document.currentScript.ownerDocument
• CORS constraints apply to documents imported
from other domains
Shadow DOM
• Encapsulate DOM parts
o The browser will know how to present those parts
o The browser won’t show the encapsulated parts in the source code
• Creates a boundary between the component and
its user
The Problems Shadow
DOM Tries to Solve
• Encapsulation of components/widgets
• Style leakage
o Leaks from one component to another
o Leaks from imported 3th party library/framework
• Global DOM
o id or class attributes all over the place
Shadow DOM in The
Browser
<video src="media/myVideo.mp4" controls></video>
<input type="date">
Show Shadow DOM
Elements in Chrome
Demo
Shadow DOM – Cont.
• Use the createShadowRoot function to wrap an
element as a shadow DOM host:
var host = document.querySelector(‘#shadowDOMHost’);
var root = host.createShadowRoot();
root.innerHTML = ‘<div>Lurking in the shadows</div>’;
Styling Shadow DOM
• :host and :host() pseudo-class
• ::content pseudo-element
<div name="myElement">
<style>
:host {
border: 1px solid lightgray;
}
</style>
<template>...</template>
</div>
Shadow DOM
Demo
Custom Elements
• Enable to extend or to create custom HTML
elements
o The new element must inherit from HTMLElement
• Create a custom element using the registerElement
function:
• Extend an existing element:
var myElement = document.registerElement(‘my-element’);
var myInput = document.registerElement(‘my-input’, {
prototype: Object.create(HTMLInputElement.prototype),
extends: ‘input’
});
Custom Elements –
Naming
• You can create named elements (almost) any way
you want:
o Same naming rules as other HTML tags
o There must be a dash (“-”) in the name
• To future-proof the name against the HTML standard
• To avoid naming collisions
Custom Elements – Usage
• Use the element in your DOM:
or use the createElement function:
<my-input></my-input>
var elm = document.createElement(‘my-input’);
Custom Element
Callbacks
• Custom elements have life cycle events:
o createdCallback
• Called when an instance is created
o attachedCallback
• Called when an instance is added to DOM subtree
o detachedCallback
• Called when an instance is removed from a DOM subtree
o attributeChangedCallback
• Called after an attribute value changes
Custom Elements
Demo
The Current State of Web
Components
• Still W3C Working Drafts
• Browser support:
http://caniuse.com/#search=web%20components
• Main libraries:
Polymer X-Tag Bosonic
Questions?
Summary
• Web Components are emerging standards that
enables:
• Encapsulation
• Separation of Concerns
• Element portability
• And more
• They are still in development
• Taking the web one step forward!
Resources
• Download the slide deck:
http://bit.ly/1OCOnbL
• http://webcomponents.org/
https://www.polymer-project.org/1.0/
http://www.x-tags.org/
• My Blog – http://www.gilfink.net
• Follow me on Twitter – @gilfink
Thank You!

More Related Content

What's hot

Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSSAndrew Rota
 
Web components the future is here
Web components   the future is hereWeb components   the future is here
Web components the future is hereGil Fink
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupGoutam Dey
 
HTML5 for ASP.NET Developers
HTML5 for ASP.NET DevelopersHTML5 for ASP.NET Developers
HTML5 for ASP.NET DevelopersJustin Lee
 
Data presentation with dust js technologies backing linkedin
Data presentation with dust js   technologies backing linkedinData presentation with dust js   technologies backing linkedin
Data presentation with dust js technologies backing linkedinRuhaim Izmeth
 
Introduction to web compoents
Introduction to web compoentsIntroduction to web compoents
Introduction to web compoentsRan Wahle
 
Brownbag on basics of web components
Brownbag on basics of web componentsBrownbag on basics of web components
Brownbag on basics of web componentsJason Park
 
20131108 cs query by howard
20131108 cs query by howard20131108 cs query by howard
20131108 cs query by howardLearningTech
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsLaurence Svekis ✔
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeLaurence Svekis ✔
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214Haim Michael
 
Web components
Web componentsWeb components
Web componentsehsanarian
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - IntroductionWebStackAcademy
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - IntroductionWebStackAcademy
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQueryGill Cleeren
 
HTML5 - Introduction
HTML5 - IntroductionHTML5 - Introduction
HTML5 - IntroductionDavy De Pauw
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - DirectivesWebStackAcademy
 

What's hot (20)

Web Components
Web ComponentsWeb Components
Web Components
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSS
 
Web components the future is here
Web components   the future is hereWeb components   the future is here
Web components the future is here
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
 
HTML5 for ASP.NET Developers
HTML5 for ASP.NET DevelopersHTML5 for ASP.NET Developers
HTML5 for ASP.NET Developers
 
Data presentation with dust js technologies backing linkedin
Data presentation with dust js   technologies backing linkedinData presentation with dust js   technologies backing linkedin
Data presentation with dust js technologies backing linkedin
 
Introduction to web compoents
Introduction to web compoentsIntroduction to web compoents
Introduction to web compoents
 
Brownbag on basics of web components
Brownbag on basics of web componentsBrownbag on basics of web components
Brownbag on basics of web components
 
20131108 cs query by howard
20131108 cs query by howard20131108 cs query by howard
20131108 cs query by howard
 
Web components
Web componentsWeb components
Web components
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applications
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive Code
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
 
Web components
Web componentsWeb components
Web components
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - Introduction
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
Dom
DomDom
Dom
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
HTML5 - Introduction
HTML5 - IntroductionHTML5 - Introduction
HTML5 - Introduction
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
 

Viewers also liked

Peranan Guru (Pemimpin Pelajar IPGM ke 2)
Peranan Guru (Pemimpin Pelajar IPGM ke 2)Peranan Guru (Pemimpin Pelajar IPGM ke 2)
Peranan Guru (Pemimpin Pelajar IPGM ke 2)Mohamed Nazul Ismail
 
[Dato' Hassan] Jabatan Perpaduan Negara & Integrasi Nasional (JPNIN)
[Dato' Hassan] Jabatan Perpaduan Negara & Integrasi Nasional (JPNIN)[Dato' Hassan] Jabatan Perpaduan Negara & Integrasi Nasional (JPNIN)
[Dato' Hassan] Jabatan Perpaduan Negara & Integrasi Nasional (JPNIN)GlobalPeaceFoundation
 
He integrasi dan menangani cabaran
He   integrasi dan menangani cabaranHe   integrasi dan menangani cabaran
He integrasi dan menangani cabarankamisah parmen
 
Cultural Diversity (1 Malaysia)
Cultural Diversity (1 Malaysia)Cultural Diversity (1 Malaysia)
Cultural Diversity (1 Malaysia)Nizam Anuar
 
Hubungan etnik - Konsep 1 Malaysia
Hubungan etnik - Konsep 1 MalaysiaHubungan etnik - Konsep 1 Malaysia
Hubungan etnik - Konsep 1 MalaysiaFatiha Akma
 
Malaysian - Multi-racial.
Malaysian - Multi-racial.Malaysian - Multi-racial.
Malaysian - Multi-racial.Malyanah Marisa
 
Bab 8 pemerkasaan pendidkan ke arah kesepaduan sosial
Bab 8   pemerkasaan pendidkan ke arah kesepaduan sosialBab 8   pemerkasaan pendidkan ke arah kesepaduan sosial
Bab 8 pemerkasaan pendidkan ke arah kesepaduan sosialMaizatul Akmal
 
Sejarah pendidikan di malaysia dan hubungan etnik
Sejarah pendidikan di malaysia dan hubungan etnikSejarah pendidikan di malaysia dan hubungan etnik
Sejarah pendidikan di malaysia dan hubungan etnikHafizah Jupri
 
CTU555 Sejarah Malaysia - Strategi Survival Melayu Bumiputera dalam Konteks H...
CTU555 Sejarah Malaysia - Strategi Survival Melayu Bumiputera dalam Konteks H...CTU555 Sejarah Malaysia - Strategi Survival Melayu Bumiputera dalam Konteks H...
CTU555 Sejarah Malaysia - Strategi Survival Melayu Bumiputera dalam Konteks H...Mahyuddin Khalid
 
2015, BAB 6 HUBUNGAN ETNIK : KEPELBAGAIAN AGAMA DI MALAYSIA
2015, BAB 6 HUBUNGAN ETNIK : KEPELBAGAIAN AGAMA DI MALAYSIA2015, BAB 6 HUBUNGAN ETNIK : KEPELBAGAIAN AGAMA DI MALAYSIA
2015, BAB 6 HUBUNGAN ETNIK : KEPELBAGAIAN AGAMA DI MALAYSIANURUL AQILAH MUSARI
 
CTU555 Sejarah Malaysia - Pengenalan
CTU555 Sejarah Malaysia - PengenalanCTU555 Sejarah Malaysia - Pengenalan
CTU555 Sejarah Malaysia - PengenalanMahyuddin Khalid
 
CTU555 Sejarah Malaysia - Kesepaduan dalam Kepelbagaian di Malaysia
CTU555 Sejarah Malaysia - Kesepaduan dalam Kepelbagaian di MalaysiaCTU555 Sejarah Malaysia - Kesepaduan dalam Kepelbagaian di Malaysia
CTU555 Sejarah Malaysia - Kesepaduan dalam Kepelbagaian di MalaysiaMahyuddin Khalid
 
CTU555 Sejarah Malaysia - Islam Hubungan Etnik
CTU555 Sejarah Malaysia - Islam Hubungan EtnikCTU555 Sejarah Malaysia - Islam Hubungan Etnik
CTU555 Sejarah Malaysia - Islam Hubungan EtnikMahyuddin Khalid
 
CTU555 Sejarah Malaysia - Hubungan Etnik ke arah Masyarakat Berintegrasi
CTU555 Sejarah Malaysia - Hubungan Etnik ke arah Masyarakat BerintegrasiCTU555 Sejarah Malaysia - Hubungan Etnik ke arah Masyarakat Berintegrasi
CTU555 Sejarah Malaysia - Hubungan Etnik ke arah Masyarakat BerintegrasiMahyuddin Khalid
 
Malaysia powerpoint show
Malaysia powerpoint showMalaysia powerpoint show
Malaysia powerpoint showcarrieanne01
 
Malaysia presentation
Malaysia presentation Malaysia presentation
Malaysia presentation khalid shah
 
Malaysia presentation
Malaysia presentationMalaysia presentation
Malaysia presentationsamhasuh
 
Culture of Malaysia - CCAP
Culture of Malaysia - CCAPCulture of Malaysia - CCAP
Culture of Malaysia - CCAPSoon-Aik Chiew
 

Viewers also liked (19)

Peranan Guru (Pemimpin Pelajar IPGM ke 2)
Peranan Guru (Pemimpin Pelajar IPGM ke 2)Peranan Guru (Pemimpin Pelajar IPGM ke 2)
Peranan Guru (Pemimpin Pelajar IPGM ke 2)
 
[Dato' Hassan] Jabatan Perpaduan Negara & Integrasi Nasional (JPNIN)
[Dato' Hassan] Jabatan Perpaduan Negara & Integrasi Nasional (JPNIN)[Dato' Hassan] Jabatan Perpaduan Negara & Integrasi Nasional (JPNIN)
[Dato' Hassan] Jabatan Perpaduan Negara & Integrasi Nasional (JPNIN)
 
He integrasi dan menangani cabaran
He   integrasi dan menangani cabaranHe   integrasi dan menangani cabaran
He integrasi dan menangani cabaran
 
Cultural Diversity (1 Malaysia)
Cultural Diversity (1 Malaysia)Cultural Diversity (1 Malaysia)
Cultural Diversity (1 Malaysia)
 
Hubungan etnik - Konsep 1 Malaysia
Hubungan etnik - Konsep 1 MalaysiaHubungan etnik - Konsep 1 Malaysia
Hubungan etnik - Konsep 1 Malaysia
 
Malaysian - Multi-racial.
Malaysian - Multi-racial.Malaysian - Multi-racial.
Malaysian - Multi-racial.
 
Hubungan etnik
Hubungan etnikHubungan etnik
Hubungan etnik
 
Bab 8 pemerkasaan pendidkan ke arah kesepaduan sosial
Bab 8   pemerkasaan pendidkan ke arah kesepaduan sosialBab 8   pemerkasaan pendidkan ke arah kesepaduan sosial
Bab 8 pemerkasaan pendidkan ke arah kesepaduan sosial
 
Sejarah pendidikan di malaysia dan hubungan etnik
Sejarah pendidikan di malaysia dan hubungan etnikSejarah pendidikan di malaysia dan hubungan etnik
Sejarah pendidikan di malaysia dan hubungan etnik
 
CTU555 Sejarah Malaysia - Strategi Survival Melayu Bumiputera dalam Konteks H...
CTU555 Sejarah Malaysia - Strategi Survival Melayu Bumiputera dalam Konteks H...CTU555 Sejarah Malaysia - Strategi Survival Melayu Bumiputera dalam Konteks H...
CTU555 Sejarah Malaysia - Strategi Survival Melayu Bumiputera dalam Konteks H...
 
2015, BAB 6 HUBUNGAN ETNIK : KEPELBAGAIAN AGAMA DI MALAYSIA
2015, BAB 6 HUBUNGAN ETNIK : KEPELBAGAIAN AGAMA DI MALAYSIA2015, BAB 6 HUBUNGAN ETNIK : KEPELBAGAIAN AGAMA DI MALAYSIA
2015, BAB 6 HUBUNGAN ETNIK : KEPELBAGAIAN AGAMA DI MALAYSIA
 
CTU555 Sejarah Malaysia - Pengenalan
CTU555 Sejarah Malaysia - PengenalanCTU555 Sejarah Malaysia - Pengenalan
CTU555 Sejarah Malaysia - Pengenalan
 
CTU555 Sejarah Malaysia - Kesepaduan dalam Kepelbagaian di Malaysia
CTU555 Sejarah Malaysia - Kesepaduan dalam Kepelbagaian di MalaysiaCTU555 Sejarah Malaysia - Kesepaduan dalam Kepelbagaian di Malaysia
CTU555 Sejarah Malaysia - Kesepaduan dalam Kepelbagaian di Malaysia
 
CTU555 Sejarah Malaysia - Islam Hubungan Etnik
CTU555 Sejarah Malaysia - Islam Hubungan EtnikCTU555 Sejarah Malaysia - Islam Hubungan Etnik
CTU555 Sejarah Malaysia - Islam Hubungan Etnik
 
CTU555 Sejarah Malaysia - Hubungan Etnik ke arah Masyarakat Berintegrasi
CTU555 Sejarah Malaysia - Hubungan Etnik ke arah Masyarakat BerintegrasiCTU555 Sejarah Malaysia - Hubungan Etnik ke arah Masyarakat Berintegrasi
CTU555 Sejarah Malaysia - Hubungan Etnik ke arah Masyarakat Berintegrasi
 
Malaysia powerpoint show
Malaysia powerpoint showMalaysia powerpoint show
Malaysia powerpoint show
 
Malaysia presentation
Malaysia presentation Malaysia presentation
Malaysia presentation
 
Malaysia presentation
Malaysia presentationMalaysia presentation
Malaysia presentation
 
Culture of Malaysia - CCAP
Culture of Malaysia - CCAPCulture of Malaysia - CCAP
Culture of Malaysia - CCAP
 

Similar to Web Components - The Future is Here

Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web componentImam Raza
 
Web components
Web componentsWeb components
Web componentsNoam Kfir
 
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...Horacio Gonzalez
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Web Components
Web ComponentsWeb Components
Web ComponentsFITC
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View EncapsulationJennifer Estrada
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handlingsmitha273566
 
Web components
Web componentsWeb components
Web componentsMohd Saeed
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introductioncherukumilli2
 
Modern Web UI - Web components
Modern Web UI - Web componentsModern Web UI - Web components
Modern Web UI - Web componentsMike North
 
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxWEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxkarthiksmart21
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScriptkoppenolski
 
BreizhBeans - Web components
BreizhBeans - Web componentsBreizhBeans - Web components
BreizhBeans - Web componentsHoracio Gonzalez
 
Webcomponents TLV October 2014
Webcomponents TLV October 2014Webcomponents TLV October 2014
Webcomponents TLV October 2014Dmitry Bakaleinik
 
Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Lee Klement
 
Web components - The Future is Here
Web components - The Future is HereWeb components - The Future is Here
Web components - The Future is HereGil Fink
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentationalledia
 

Similar to Web Components - The Future is Here (20)

Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web component
 
Web components
Web componentsWeb components
Web components
 
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Web Components
Web ComponentsWeb Components
Web Components
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
 
Polymer
PolymerPolymer
Polymer
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handling
 
Web components
Web componentsWeb components
Web components
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
Modern Web UI - Web components
Modern Web UI - Web componentsModern Web UI - Web components
Modern Web UI - Web components
 
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxWEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptx
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
 
BreizhBeans - Web components
BreizhBeans - Web componentsBreizhBeans - Web components
BreizhBeans - Web components
 
Webcomponents TLV October 2014
Webcomponents TLV October 2014Webcomponents TLV October 2014
Webcomponents TLV October 2014
 
Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012
 
Manasa
ManasaManasa
Manasa
 
Web components - The Future is Here
Web components - The Future is HereWeb components - The Future is Here
Web components - The Future is Here
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentation
 
Polymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot CampPolymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot Camp
 

More from Gil Fink

Becoming a Tech Speaker
Becoming a Tech SpeakerBecoming a Tech Speaker
Becoming a Tech SpeakerGil Fink
 
Web animation on steroids web animation api
Web animation on steroids web animation api Web animation on steroids web animation api
Web animation on steroids web animation api Gil Fink
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Stencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedStencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedGil Fink
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Being a tech speaker
Being a tech speakerBeing a tech speaker
Being a tech speakerGil Fink
 
Working with Data in Service Workers
Working with Data in Service WorkersWorking with Data in Service Workers
Working with Data in Service WorkersGil Fink
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular AnimationsGil Fink
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angularGil Fink
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angularGil Fink
 
Who's afraid of front end databases?
Who's afraid of front end databases?Who's afraid of front end databases?
Who's afraid of front end databases?Gil Fink
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type scriptGil Fink
 
End to-end apps with type script
End to-end apps with type scriptEnd to-end apps with type script
End to-end apps with type scriptGil Fink
 
Redux data flow with angular 2
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2Gil Fink
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSGil Fink
 
Who's afraid of front end databases
Who's afraid of front end databasesWho's afraid of front end databases
Who's afraid of front end databasesGil Fink
 
Biological modeling, powered by angular js
Biological modeling, powered by angular jsBiological modeling, powered by angular js
Biological modeling, powered by angular jsGil Fink
 
Whos afraid of front end databases?
Whos afraid of front end databases?Whos afraid of front end databases?
Whos afraid of front end databases?Gil Fink
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type scriptGil Fink
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScriptGil Fink
 

More from Gil Fink (20)

Becoming a Tech Speaker
Becoming a Tech SpeakerBecoming a Tech Speaker
Becoming a Tech Speaker
 
Web animation on steroids web animation api
Web animation on steroids web animation api Web animation on steroids web animation api
Web animation on steroids web animation api
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Stencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedStencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has Arrived
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Being a tech speaker
Being a tech speakerBeing a tech speaker
Being a tech speaker
 
Working with Data in Service Workers
Working with Data in Service WorkersWorking with Data in Service Workers
Working with Data in Service Workers
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular Animations
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
Who's afraid of front end databases?
Who's afraid of front end databases?Who's afraid of front end databases?
Who's afraid of front end databases?
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type script
 
End to-end apps with type script
End to-end apps with type scriptEnd to-end apps with type script
End to-end apps with type script
 
Redux data flow with angular 2
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJS
 
Who's afraid of front end databases
Who's afraid of front end databasesWho's afraid of front end databases
Who's afraid of front end databases
 
Biological modeling, powered by angular js
Biological modeling, powered by angular jsBiological modeling, powered by angular js
Biological modeling, powered by angular js
 
Whos afraid of front end databases?
Whos afraid of front end databases?Whos afraid of front end databases?
Whos afraid of front end databases?
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type script
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
 

Recently uploaded

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Web Components - The Future is Here

  • 1. Web Components - The Future is Here Gil Fink CEO and Senior Consultant, sparXys
  • 3. About Me • sparXys CEO and senior consultant • ASP.NET/IIS Microsoft MVP in the last 7 years • Pro Single Page Application Development (Apress) co-author • 4 Microsoft Official Courses (MOCs) co-author • GDG Rashlatz and ng-conf Israel co-organizer
  • 4. Agenda • The problems we face • Web Components APIs o Templates o Imports o Shadow DOM o Custom Elements
  • 6. 2. Poor Separation of Concerns You want HTML, CSS and JavaScript to work together You end up with a mess The wiring gets in your way!
  • 7. 3. No Native Templates • Store HTML in hidden DOM element and show it • Use script tag as a template holder: <script id=”myTemplate” type=”text/template”> <div> … </div> </script>
  • 8. 4. No Bundling • You want to bundle a complex component The component includes HTML, CSS and JavaScript how would you do that? o Use a server side wrapping mechanism?
  • 9. Web Components to the Rescue • A set of standards designed to componentize the web • Some general goals: Code Reuse Encapsulation Separation of Concerns Composition Theming Expressive Semantic
  • 10. The Web Components Standards •Reusable DOM fragmentsTemplates •Load HTML declarativelyImports •DOM encapsulationShadow DOM •Create your own elements Custom Elements
  • 11. Setting The Environment • Browsers have only partial support for Web Components o So we use the webcomponents.js Polyfill for Web Components • Download: o https://github.com/webcomponents/webcomponentsjs/ o Or install using your favorite package manager (NPM, Bower, Nuget) • Make sure the Polyfill script runs first
  • 14. Templates • A new HTML element – template o Can be used to instantiate document fragments o Can wrap HTML, style tags and script tags • No data binding support  • To use a template you need to write some JavaScript code <template id=”myTemplate”> <div> … </div> </template>
  • 15. Cloning a Template • Select the template and extract its content o Using its content property • Use the importNode function to get the cloned content • Only when the clone is appended to the DOM o The style and JavaScript are executed o Resources such as images are fetched from the server var template = document.querySelector(‘#myTemplate’); var clone = document.importNode(template.content, true);
  • 17. Imports • Load additional HTML documents o Without Ajax • A new type of link tag • Use the rel attribute with the import type: <link rel=”import” href=”myImport.html”>
  • 18. Imports and Bundling • Enable to bundle a full component into one HTML file o The HTML can include scripts and styles • The whole bundle can be retrieved in a single call
  • 19. Imports and The DOM • Importing a document doesn’t include it into the DOM o It will parse it in memory and load all the additional resources • Use the import property of the link tag: var content = document.querySelector(‘link[rel=”import”]’).import;
  • 21. Import Notes • Scripts running inside the import can reference the containing document o By calling document.currentScript.ownerDocument • CORS constraints apply to documents imported from other domains
  • 22. Shadow DOM • Encapsulate DOM parts o The browser will know how to present those parts o The browser won’t show the encapsulated parts in the source code • Creates a boundary between the component and its user
  • 23. The Problems Shadow DOM Tries to Solve • Encapsulation of components/widgets • Style leakage o Leaks from one component to another o Leaks from imported 3th party library/framework • Global DOM o id or class attributes all over the place
  • 24. Shadow DOM in The Browser <video src="media/myVideo.mp4" controls></video> <input type="date">
  • 25. Show Shadow DOM Elements in Chrome Demo
  • 26. Shadow DOM – Cont. • Use the createShadowRoot function to wrap an element as a shadow DOM host: var host = document.querySelector(‘#shadowDOMHost’); var root = host.createShadowRoot(); root.innerHTML = ‘<div>Lurking in the shadows</div>’;
  • 27. Styling Shadow DOM • :host and :host() pseudo-class • ::content pseudo-element <div name="myElement"> <style> :host { border: 1px solid lightgray; } </style> <template>...</template> </div>
  • 29. Custom Elements • Enable to extend or to create custom HTML elements o The new element must inherit from HTMLElement • Create a custom element using the registerElement function: • Extend an existing element: var myElement = document.registerElement(‘my-element’); var myInput = document.registerElement(‘my-input’, { prototype: Object.create(HTMLInputElement.prototype), extends: ‘input’ });
  • 30. Custom Elements – Naming • You can create named elements (almost) any way you want: o Same naming rules as other HTML tags o There must be a dash (“-”) in the name • To future-proof the name against the HTML standard • To avoid naming collisions
  • 31. Custom Elements – Usage • Use the element in your DOM: or use the createElement function: <my-input></my-input> var elm = document.createElement(‘my-input’);
  • 32. Custom Element Callbacks • Custom elements have life cycle events: o createdCallback • Called when an instance is created o attachedCallback • Called when an instance is added to DOM subtree o detachedCallback • Called when an instance is removed from a DOM subtree o attributeChangedCallback • Called after an attribute value changes
  • 34. The Current State of Web Components • Still W3C Working Drafts • Browser support: http://caniuse.com/#search=web%20components • Main libraries: Polymer X-Tag Bosonic
  • 36. Summary • Web Components are emerging standards that enables: • Encapsulation • Separation of Concerns • Element portability • And more • They are still in development • Taking the web one step forward!
  • 37. Resources • Download the slide deck: http://bit.ly/1OCOnbL • http://webcomponents.org/ https://www.polymer-project.org/1.0/ http://www.x-tags.org/ • My Blog – http://www.gilfink.net • Follow me on Twitter – @gilfink