Dominik Lubański
JavaScript Expert, Frontend Architect, and Team Leader with 10+ years of experience in web development. Taking roles in a wide range of projects with software houses, media agencies, rising startups, and other technology companies.
live slides: goo.gl/ofHnzr
<video width="480" controls poster="webmvp8.gif">
<source src="webmvp8.webm" type="video/webm">
<source src="webmvp8_512kb.mp4" type="video/mp4">
<source src="webmvp8.ogv" type="video/ogg">
Your browser doesn't support HTML5 video tag.
</video>
attributes
children elements
Internal structure
const video = document.createElement('video');
video.play();
video.pause();
video.addEventListener('loadedmetadata', ...);
methods
events
video.controls = true;
video.poster = 'image.png';
properties
events
attributes
& properties
methods
play(), pause(),
etc...
src, poster, autoplay, etc..
internal DOM structure
canplay, pause, play, playing, ratechange, timeupdate, volumechange, error, etc...
Shadow DOM replaces element content with DOM subtree not directly connected to document.
Style rules are scoped. CSS selectors like id and class do not apply to elements outside.
<style>
#my-id { color: red }
</style>
<div id="my-id">
Text
</div>
Shadow DOM Slot API allows flexibly distribute content to Shadow DOM.
<div id="wrapper">
<slot name="title"></slot>
</div>
<slot></slot>
const div = document.createElement('div');
Or 'closed'
const shadowRoot = div.attachShadow({ mode: 'open' });
div.shadowRoot === shadowRoot // For 'open' mode
shadowRoot instanceof DocumentFragment === true;
// We can add some content
shadowRoot.innerHTML = '<p>Some paragraph</p>';
div.children.length === 0; // true
Custom Elements API allows to define new elements.
<my-carousel swipe arrows>
<my-carousel-item name="Item 1">
<img src="image-1.png" />
</my-carousel-item>
<my-carousel-item name="Item 1">
<img src="image-1.png" />
</my-carousel-item>
</my-carousel>
class MyElement extends HTMLElement {
constructor() {
super();
this.textContent = 'Sample text';
}
get something() { ... }
myMethod() { ... }
}
customElements.define('my-element', MyElement);
standards
own standards
v33 (02/2014)
v25 (prefix) (02/2013), v35 (05/2014)
v40
in dev
v53
v10
in dev
v41
in dev
v54
in dev
in dev
Templates declare fragments of DOM which can be activated later at runtime.
<template id="my-template">
<h1>Title</h1>
<img src="image.png" />
</template>
deferred request
Templates are implemented in every modern browser.
v15
v22
v26
v7.1
v13
HTML Imports are a way of including HTML documents in other documents.
<head>
...
<link rel="import" href="bootstrap.html">
</head>
HTML file may contains styles, templates, scripts, css, etc...
<link rel="stylesheet" href="bootstrap.css">
<script src="jquery.js"></script>
<script src="bootstrap.js"></script>
...
<template id="my-element">...</template>
<script> customElements.define(...) </script>
import 'bootstrap.css';
import jQuery from 'jquery';
import bootstrap from 'bootstrap';
const template = '...';
customElements.define(...);
Mozilla and Webkit will not implement html imports in favor of ES6 Modules.
v23
v36
U/C
events
attributes
& properties
prototype methods
attributeChangedCallback,
prototype properties
Shadow DOM
+ Template
custom events dispatched on element
instance
The most important specifications are shipped,
in development or can be polyfilled/shimmed.
Web components are great way to unify
creating UI libraries.
Web components will never replace JS frameworks.
By Dominik Lubański
What really are web components? How they work? Can we use them today?
JavaScript Expert, Frontend Architect, and Team Leader with 10+ years of experience in web development. Taking roles in a wide range of projects with software houses, media agencies, rising startups, and other technology companies.