Are Web Components the Betamax of web development? Horacio Gonzalez @LostInBrittany
Slide 2
Who are we? Introducing myself and introducing OVH OVHcloud
Slide 3
Horacio Gonzalez @LostInBrittany Spaniard lost in Brittany, developer, dreamer and all-around geek
Flutter
Slide 4
OVHcloud: A global leader Web Cloud & Telcom
30 Data Centers in 12 locations
1 Million+ Servers produced since 1999
Private Cloud
34 Points of Presence on a 20 TBPS Bandwidth Network
1.5 Million Customers across 132 countries
Public Cloud
2200 Employees worldwide
3.8 Million Websites hosting
Storage
115K Private Cloud VMS running
1.5 Billion Euros Invested since 2016
300K Public Cloud instances running
P.U.E. 1.09 Energy efficiency indicator
380K Physical Servers running in our data centers
20 Years in Business Disrupting since 1999
Network & Security
Slide 5
OVHcloud & Poland
● Klaba family comes from Poland ● OVHcloud data center in Warsaw ● OVHcloud office in Wroclaw
Slide 6
Sometimes I feel a bit grumpy The stories of the grumpy old speaker…
Slide 7
On Web Components tour since 2014
Slide 8
Image: bu.edu
Web components == Revolution
Slide 9
Images: BitRebels & Brickset
Building a world brick by brick
Slide 10
Is the promise unfulfilled? It’s 2019 now, where is your revolution, dude?
Slide 11
And, even worse, several months ago Hey, dude, your Web Components thing is like Betamax Even if it was a better solution, market has already chosen, React has won, as VHS did…
Slide 12
The 3 minutes context What the heck are web component?
Slide 13
Web Components
Web standard W3C
Slide 14
Web Components
Available in all modern browsers: Firefox, Safari, Chrome
Slide 15
Web Components
Create your own HTML tags Encapsulating look and behavior
Slide 16
Web Components
Fully interoperable With other web components, with any framework
Slide 17
Web Components
CUSTOM ELEMENTS
SHADOW DOM
TEMPLATES
Slide 18
Custom Element To define your own HTML tag <body> … <script> window.customElements.define(‘my-element’, class extends HTMLElement {…}); </script> <my-element></my-element> </body>
Slide 19
Shadow DOM To encapsulate subtree and style in an element <button>Hello, world!</button> <script> var host = document.querySelector(‘button’); const shadowRoot = host.attachShadow({mode:’open’}); shadowRoot.textContent = ‘こんにちは、影の世界!’; </script>
Slide 20
Template To have clonable document template <template id=”mytemplate”> <img src=”” alt=”great image”> <div class=”comment”></div> </template> var t = document.querySelector(‘#mytemplate’); // Populate the src at runtime. t.content.querySelector(‘img’).src = ‘logo.png’; var clone = document.importNode(t.content, true); document.body.appendChild(clone);
Slide 21
But in fact, it’s just an element…
● ● ● ●
Attributes Properties Methods Events
Slide 22
Hey, old man, WTF is a Betamax? A videocassette guide for Millenials
Slide 23
At the beginning there was the TV
And public saw it was good…
Slide 24
But how to keep your favorite show forever?
Sony VTR CV-2000 - Image credit LabGuy’s World
The VTR was born, somewhere in the 1960s
Slide 25
From videotape to videocassette…
Sony U-matic - Image credit MKH Electronics
U-matic cassette - Image credit PSAP
And then to mass market, sometime in the 1970s
Slide 26
Each vendor proposed their solution
Sony’s Betamax - Image credit PSAP
JVC’s VHS - Image credit PSAP
Cassettes aren’t so different from JS frameworks after all…
Slide 27
Slide 28
There was a format war
So fierce that it has its own Wikipedia page
Slide 29
Betamax was a superior format
Higher quality recorders, better resolution, slightly superior sound, and more stable image
Slide 30
But the market decided otherwise
And Betamax, even if superior, failed…
Slide 31
As usual, the winner took it all
Until a new arrival entered in scene, the DVD… But that’s another story for another talk
Slide 32
Why did Betamax failed? Spoiler: it isn’t so simple…
Slide 33
Betamax was believed to be superior
In the minds of the public and press
Slide 34
But consumers wanted an affordable VCR
Betamax costed hundreds of dollars more
Slide 35
They also wanted to record a full movie
Originally Betamax cassettes only recorded 1 hour
Slide 36
And compatibility weighted on VHS side
Many licencees offered VHS VCRs
Slide 37
Are Web Components like Betamax? A perceived superior alternative destined to fail?
Slide 38
It could be even the opposite…
Web components are maybe the VHS of JS
Slide 39
Compatibility is on Web Components side
Web Components everywhere, baby!
Slide 40
Do you remember AngularJS?
And all the code put in the trash bin when Angular arrived…
Slide 41
The pain of switching frameworks?
Rewriting once again your code…
Slide 42
The impossibility of sharing UI code?
Between apps written with different frameworks
Slide 43
Web Components change that
In a clean and standard way
Slide 44
They are indeed a revolution
But it’s a silent one…
Slide 45
They are there, in everyday sites
More than you can imagine
Slide 46
The components architecture won
Components, components everywhere
Slide 47
Web components ARE platform
Truly part of the platform…
Slide 48
Aren’t the multiple Web Components libs a sign of failure? If the standard worked, people would use Vanilla, wouldn’t them?
Slide 49
Web component standard is low level
At it should be!
Slide 50
Standard == basic bricks Standard exposes an API to: ○ Define elements ○ Encapsulate DOM
Slide 51
Libraries are helpers
They give you higher-level primitives
Slide 52
Different high-level primitives
Each one tailored to a use
Slide 53
Sharing the same base
High-performant, low-level, in-the-platform web components standard
Slide 54
Libraries aren’t a failure of standard
They happen by design
Slide 55
Stencil Powering Ionic 4+
Slide 56
Not another library
A Web Component toolchain
Slide 57
A mature technology
Ionic 4 released on year ago, powered by Stencil!
Slide 58
Built by the Ionic team
Tired of putting good code in the trash bin…
Slide 59
A build time tool
To generate standard web components
Slide 60
Fully featured ●
Web Component-based
●
Component pre-rendering
●
Asynchronous rendering pipeline
●
Simple component lazy-loading
●
TypeScript support
●
JSX support
●
One-way Data Binding
●
Dependency-free components
Slide 61
And the cherry on the cake
Server-Side Rendering
Slide 62
Stencil leverages the web platform
Working with the web, not against it
What’s Polymer status today?
Well, how could I say… it’s complicated
Slide 66
It seems it’s going to be deprecated…
Technically yes… and that means good news!
Slide 67
Let’s try to see clearer
Let’s dive into Polymer history…
Slide 68
A tool built for another paradigm
No web component support on browsers No React, Angular or Vue innovations
Slide 69
No so well suited for the current one
The current platform is way more powerful The state of art has evolved
Slide 70
Let’s learn from its lessons
The current platform is way more powerful The state of art has evolved
Slide 71
And let it rest…
There will have no Polymer 4…
Slide 72
So Polymer as we know it is dead…
But the Polymer Project is indeed alive!
Slide 73
But I have invested so much on it!
What to do?
Slide 74
That’s why web components are top
You can keep using all your Polymer components and create the new ones with a new library… And it simply works!
Slide 75
And without metaphors?
Polymer Project != Polymer library Polymer Project well alive Polymer library was only one library
Slide 76
LitElement New kid on the block
Slide 77
Born from the Polymer team
For the new web paradigm
Slide 78
Modern lightweight web components
For the new web paradigm
Slide 79
Based on lit-html
An efficient, expressive, extensible HTML templating library for JavaScript
Slide 80
Do you know tagged templates? function uppercaseExpression(strings, …expressionValues) { var finalString = ” for ( let i = 0; i < strings.length; i++ ) { if (i > 0) { finalString += expressionValues[i - 1].toUpperCase() } finalString += strings[i] } return finalString } const
expressions = [ ‘Milan’, ‘Codemotion Milan’,
‘Thank you’];
console.log( uppercaseExpressionI am so happy to be in ${expressions[0]} for ${expressions[1]} ! ${expressions[2]}, ${expressions[1]}! )
Little known functionality of template literals
Slide 81
lit-html Templates
let myTemplate = (data) => html<h1>${data.title}</h1> <p>${data.body}</p>;
Lazily rendered Generates a TemplateResult
Slide 82
It’s a bit like JSX, isn’t it?
The good sides of JSX… but in the standard!
Slide 83
LitElement import { LitElement, html } from ‘lit-element’; // Create your custom component class CustomGreeting extends LitElement { // Declare properties static get properties() { return { name: { type: String } }; } // Initialize properties constructor() { super(); this.name = ‘World’; } // Define a template render() { return html<p>Hello, ${this.name}!</p>; } } // Register the element with the browser customElements.define(‘custom-greeting’, CustomGreeting);
Lightweight web-components using lit-html
Slide 84
One more thing…* Let’s copy from the master
Slide 85
Polymer is not important
WebComponents ARE
Slide 86
Use the Platform, Luke…
WebComponents ARE native
Slide 87
Do you love your framework?
Oh yeah, we all do
Slide 88
Would you marry your framework?
Like until death…
Slide 89
How much does cost the divorce?
Do you remember when you dropped AngularJS for Angular?
Slide 90
Why recode everything again?
Reuse the bricks in your new framework
Slide 91
Lots of web components libraries LitElement SkateJS
For different need and sensibilities
Slide 92
And some good news
Angular Elements
Vue Web Component Wrapper
Frameworks begin to understand it
Slide 93
So for your next app Choose a framework, no problem… But please, help your future self
Use Web Components!