progressive web components · 2016-11-17 · progressive web components ... be as good as native...

60

Upload: others

Post on 20-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according
Page 2: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Progressive Web Components

Frederik Dohr, @fndStefan Tilkov, @stilkov

GOTO Berlin 2016

Page 3: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

History repeating …

CORBAWeb

WS-*REST

Page 4: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

What’s the client side analogy?

Page 5: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

“Web service”1) > Use HTTP as transport

> Ignore verbs

> Ignores URIs

> Expose single “endpoint”

> Fails to embrace the Web

1) in the SOAP/WSDL sense

> Uses browser as runtime

> Ignores forward, back, refresh

> Does not support linking

> Exposes monolithic “app”

> Fails to embrace the browser

2) built as a careless SPA

“Web app”2)

Page 6: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Desktop-style single-page apps: The browser’s WS-*

Page 7: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Assumption: JS-centric web apps can

be as good as native apps

They shouldn’t be as bad!

Page 8: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Simple two-step secret to improving the performance of any website, according to Maciej Ceglowski (@baconmeteor):

“1. Make sure that the most important elements of the page download and render first. 2. Stop there.”

http://idlewords.com/talks/website_obesity.htm

Page 9: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

JavaScript framework tax

bloatcomplexity

dependency

technical debt

Page 10: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

The web-native way of distributing logic

Process Flow

Presentation

Domain Logic

Data

Server

Client > Rendering, layout, stylingon an unknown client

> Logic & state machine on server

> Client user-agent extensible viacode on demand

Page 11: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

ROCA: Resource-oriented Client Architecture http://roca-style.org

Page 12: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Framework?

We don’t need no stinking framework

Maybe we do

Page 13: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Framework benefits

folklorearchitecture opinion

communityskills

components

component model

Page 14: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

🙏

Page 15: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

SPAs : web development :: Trump : democracy

Page 16: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Any sufficiently complicated JavaScript client application contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half a browser.

— Stefan Tilkov, with apologies to Phillip Greenspun

Page 17: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Hard to put into words how utterly broken JS-first web development is. So many parts of the system work against you when you take the reins.

— Alex Russell (@slightlylate)

Page 18: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Browser Platform

Component

JavaScript Framework

Component Component Component

date pickertask list

shopping cart

media player

Application

Page 19: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

< >

Page 20: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<video >

Page 21: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<video src="bunny.mp4" controls>

Page 22: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<video src="bunny.mp4" controls> <track kind="subtitles" …> </video>

play / pause

.play() / .pause()

Page 23: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

source: Big Buck Bunny

Page 24: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

The browser is the framework

#UseThePlatform

Page 25: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Browser Platform

Component

Application

JavaScript Framework

Component Component Component

Page 26: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

😱😱

Browser Platform

Application

JavaScript Framework

Component Component

Page 27: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Browser Platform

ComponentComponent Component Component

Application

Component

Page 28: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Component

<audio src="meow.mp4" controls>

Browser Platform

ComponentComponent Component

Application

Page 29: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Component

Browser Platform

ComponentComponent Component

Glue Code

Application

Page 30: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<input type="text" class="date">

$("input.date").datepicker();

Page 31: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<div class="tabs">

<ul>

<li> <a href="#about">About</a>

<li> <a href="#comments">Discussion</a>

</ul>

<p id="about">lorem ipsum dolor sit amet</p>

<ol id="comments"> … </ol>

</div>

$(".tabs").tabs();

Page 32: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<div class="tabs">

<ul>

<li> <a href="#about">About</a>

<li> <a href="#comments">Discussion</a>

</ul>

<p id="about">lorem ipsum dolor sit amet</p>

<ol id="comments"> … </ol>

</div>

$(".tabs").tabs();

Page 33: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<div class="tabs">

<ul>

<li> <a href="#about">About</a>

<li> <a href="#comments">Discussion</a>

</ul>

<p id="about">lorem ipsum dolor sit amet</p>

<ol id="comments"> … </ol>

</div>

$(".tabs").tabs();

🎉 Unobtrusive JavaScript 🎉

Page 34: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Component

Browser Platform

ComponentComponent Component

Glue Code

HTMLJSCS

S

HTML

JSCSS

HTML

JSCSS

HTML

JSCSS

👌 Progressive Enhancement 👍

Page 35: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Component

Browser Platform

ComponentComponent Component

Glue Code

HTMLJSCS

S

HTML

JSCSS

HTML

JSCSS

HTML

JSCSS

👌 Progressive Enhancement 👍

Progressive enhancement is not about dealing with old browsers, it's about dealing with new browsers.

— Jeremy Keith (@adactio)

Page 36: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<div class="tabs">

<ul>

<li> <a href="#about">About</a>

<li> <a href="#comments">Discussion</a>

</ul>

<p id="about">lorem ipsum dolor sit amet</p>

<ol id="comments"> … </ol>

</div>

$(".tabs").tabs();

Page 37: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<tab-nav>

<ul>

<li> <a href="#about">About</a>

<li> <a href="#comments">Discussion</a>

</ul>

</tab-nav>

<p id="about">lorem ipsum dolor sit amet</p>

<ol id="comments"> … </ol>

$(".tabs").tabs();

Page 38: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<tab-nav>

<ul>

<li> <a href="#about">About</a>

<li> <a href="#comments">Discussion</a>

</ul>

</tab-nav>

<tab-contents>

<p id="about">lorem ipsum dolor sit amet</p>

<ol id="comments"> … </ol>

</tab-contents>

$(".tabs").tabs();

Page 39: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<ul is="tab-nav">

<li> <a href="#about">About</a>

<li> <a href="#comments">Discussion</a>

</ul>

<tab-contents>

<p id="about">lorem ipsum dolor sit amet</p>

<ol id="comments"> … </ol>

</tab-contents>

$(".tabs").tabs();

Page 40: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

<ul is="tab-nav">

<li> <a href="#about">About</a>

<li> <a href="#comments">Discussion</a>

</ul>

<tab-contents>

<p id="about">lorem ipsum dolor sit amet</p>

<ol id="comments"> … </ol>

</tab-contents>

📄 Custom Elements📄

Page 41: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

customElements.define("task-list");

Page 42: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

customElements.define("task-list", TaskList);

class TaskList extends HTMLElement {}

Page 43: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

customElements.define("task-list", TaskList);

class TaskList extends HTMLElement { constructor() { // element created or upgraded super(); … }

connectedCallback() { // element inserted into the DOM … }

disconnectedCallback() { // element removed from the DOM … } }

Page 44: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

customElements.define("task-list", TaskList);

class TaskList extends HTMLElement { …

attributeChangedCallback(attrName, oldVal, newVal) { … }

static get observedAttributes() { return ["theme"]; } }

Page 45: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

customElements.define("task-list", TaskList);

class TaskList extends HTMLElement { …

connectedCallback() { let obs = new MutationObserver(this.onChange); obs.observe(this, { childList: true, subtree: true }); }

onChange() { … } }

Page 46: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

customElements.define("task-list", TaskList);

class TaskList extends HTMLElement { …

connectedCallback() { let shadowRoot = this.attachShadow({ mode: "open" }); shadowRoot.innerHTML = "<canvas></canvas>"; … }

… }

📄 Shadow DOM📄

Page 47: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Component

Browser Platform

ComponentComponent Component

Glue Code

Page 48: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Component

Browser Platform

ComponentComponent Component

Glue Code

📄 Custom Elements📄

Boring Is Good

Page 49: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Component

Browser Platform Component

Component

Glue Code

Component

image source: Openclipart/atlantis

Page 50: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Component

Browser Platform Component

Component

Glue Code

Component

image source: Openclipart/atlantis

Style Guides

&

Component Libraries

Page 51: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Wrap-up

Page 52: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Backend platform goals

> As few assumptions as possible

> No implementation dependencies

> Small interface surface

> Based on standards

> Parallel development

> Independent deployment

> Autonomous operations

Backend Platform

Page 53: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

What’s the frontend platform analogy?

> As few assumptions as possible

> No implementation dependencies

> Small interface surface

> Based on standards

> Parallel development

> Independent deployment

> Autonomous operations

Backend Platform

Frontend Platform

Page 54: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

The browser as a platform

> Independent applications

> Loosely coupled

> Separately deployable

> Based on standard platform

> Updated on the fly

> Any device

Backend Platform

Frontend Platform

Page 55: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Summary

Page 56: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Embracing the browsers constraints provides benefits

Page 57: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

JS Frameworks provide a proprietary architecture

Page 58: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Web components offer a standardized way to get the best

of both worlds

Page 59: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according

Frederik Dohr [email protected]

innoQ Deutschland GmbH

Krischerstr. 100 40789 Monheim am Rhein Germany Phone: +49 2173 3366-0

innoQ Schweiz GmbH

Gewerbestr. 11 CH-6330 Cham Switzerland Phone: +41 41 743 0116www.innoq.com

Ohlauer Straße 43 10999 Berlin Germany Phone: +49 2173 3366-0

Ludwigstr. 180E 63067 Offenbach    Germany Phone: +49 2173 3366-0

Kreuzstraße 1680331 München Germany Phone: +49 2173 3366-0

Thank you – that’s all we have.

@fnd

Stefan [email protected]

@stilkov

Page 60: Progressive Web Components · 2016-11-17 · Progressive Web Components ... be as good as native apps ad! Simple two-step secret to improving the performance of any website, according