Transcript
Page 1: High Performance Web Components

Web Components

@souders

stevesouders.com/docs/sfwebperf-20140429.pptx flickr.com/photos/brenderous/4255550788

Page 2: High Performance Web Components
Page 3: High Performance Web Components

flickr.com/photos/brenderous/4255550788

Page 4: High Performance Web Components
Page 5: High Performance Web Components
Page 6: High Performance Web Components
Page 7: High Performance Web Components
Page 8: High Performance Web Components
Page 9: High Performance Web Components
Page 10: High Performance Web Components
Page 11: High Performance Web Components

bigqueri.es/t/what-is-the-distribution-of-1st-party-vs-3rd-party-resources/100

Page 12: High Performance Web Components

flickr.com/photos/brenderous/4255550788

Page 13: High Performance Web Components

flickr.com/photos/countylemonade/5940567593

Page 14: High Performance Web Components

SPOF

flickr.com/photos/darwinbell/465459020/

Page 15: High Performance Web Components

en.wikipedia.org/wiki/Single_point_of_failure

Page 16: High Performance Web Components

Frontend SPOF

Page 17: High Performance Web Components

flickr.com/photos/runneralan/9741423581

scripts

stylesheets

fonts

Page 18: High Performance Web Components
Page 19: High Performance Web Components
Page 20: High Performance Web Components
Page 21: High Performance Web Components

flickr.com/photos/krhamm/171302038

sync

Page 22: High Performance Web Components

flickr.com/photos/8229345@N02/7980116331

async

Page 23: High Performance Web Components

load scripts asyncvar s0 = document. getElementsByTagName('script')[0];

var s1 = document. createElement('script');

s1.async = true;

s1.src = 'common.js';

s0.parentNode.insertBefore(s1, s0);

Page 24: High Performance Web Components

https://www.flickr.com/photos/thisisbossi/3069180895

Page 25: High Performance Web Components
Page 26: High Performance Web Components

HTML Templates

Shadow DOM

HTML Imports

Custom Elements

Page 27: High Performance Web Components

HTML Templates

Shadow DOM

HTML Imports

Custom Elements

Page 28: High Performance Web Components
Page 29: High Performance Web Components

SupportChrome 33-34 with

chrome://flags/• experimental Web Platform

features• Experimental JavaScript• HTML Imports

Chrome 36+: no flags

Polymer: http://www.polymer-project.org/

flickr.com/photos/callumscott2/167684986

Page 30: High Performance Web Components

HTML Imports<link rel="import" href="navtiming.php">

navtiming.php:<div id='navtiming-content'><input type=button value='Nav Timing' onclick='doNavTiming()'></div><script>function doNavTiming() {…

Page 31: High Performance Web Components

HTML Imports<link rel="import" href="navtiming.php">

navtiming.php:<div id='navtiming-content'><input type=button value='Nav Timing' onclick='doNavTiming()'></div><script>function doNavTiming() {…

Page 32: High Performance Web Components

insert imported HTML

var link = document. querySelector('link[rel=import]');

var content = link.import. querySelector('#navtiming-content');

document.getElementById('target'). appendChild(content.cloneNode(true));

Page 33: High Performance Web Components

<html> <head>

<link rel="import" href="navtiming.php"></head> <body>

<div id="target"></div>

<script>var link = document. querySelector('link[rel=import]');

var content = link.import. querySelector('#navtiming-content');

document.getElementById('target'). appendChild(content.cloneNode(true));

</script>

</body> </html>

Race Condition?

Page 34: High Performance Web Components

<html> <head>

<link rel="import" href="navtiming.php"></head> <body>

<div id="target"></div>

<script>var link = document. querySelector('link[rel=import]');

var content = link.import. querySelector('#navtiming-content');

document.getElementById('target'). appendChild(content.cloneNode(true));

</script>

</body> </html>

Race Condition!

Page 35: High Performance Web Components

resolution: BLOCK

Chrome 33-34:stop parsing at 1st SCRIPT tag

Chrome 36:stop parsing immediately – entire BODY is blocked from rendering• start rendering after ~5

seconds• block at first script

flickr.com/photos/runneralan/9741423581

Page 36: High Performance Web Components

HTML Templates

Shadow DOM

HTML Imports

Custom Elements

Page 37: High Performance Web Components

Custom Elements<link rel="import" href="navtimingce.php">

navtimingce.php:<script>var NavTimingProto = Object.create(HTMLElement.prototype);

NavTimingProto.createdCallback = function(){ this.innerHTML = "<input type=button…>"; };

document.registerElement('nav-timing', {prototype: NavTimingProto});

function doNavTiming() {… MUST have hyphen!

Page 38: High Performance Web Components

insert custom element

<nav-timing></nav-timing>

That's it!

Page 39: High Performance Web Components

<html> <head>

<link rel="import" href="navtimingce.php">

</head> <body>

<nav-timing></nav-timing></body> </html>

Race Condition?

Page 40: High Performance Web Components

<html> <head>

<link rel="import" href="navtimingce.php">

</head> <body>

<nav-timing></nav-timing></body> </html>

Race Condition!

Page 41: High Performance Web Components

solution: BLOCK

Chrome 33-34:stop parsing at 1st SCRIPT tag

Chrome 36:stop parsing immediately – entire BODY is blocked from rendering

all:ignore hyphenated tags if not registered

flickr.com/photos/runneralan/9741423581

Page 42: High Performance Web Components

load HTML Imports async

var link = document. createElement('link');

link.rel = 'import';

link.onload = function() { var link = document.querySelector('link[rel=import]');var content = link.import.querySelector('#navtiming-content');document.getElementById('target').appendChild(content.cloneNode(true));

};

link.href = 'navtiming.php';

document.getElementsByTagName ('head')[0].appendChild(link);

Page 43: High Performance Web Components

suggested fixes

"lazyload" attribute

"elements" attribute

make LINK valid w/in BODY

flickr.com/photos/chudo1909/6979697127

Page 44: High Performance Web Components

HTML Imports block rendering

workarounds (hacks) exist

need to change the spec

check your site for Frontend SPOF

takeaways

Page 45: High Performance Web Components

Steve Souders

@souders

stevesouders.com/docs/sfwebperf-webcomp-20140429.pptx


Top Related