high performance html5 - o'reilly velocity china 2016 web...

50
flickr.com/photos/djbiesack/85833076/ High Performance HTML5 stevesouders.com/docs/velocity-html5-20111207.pptx Disclaimer: This content does not necessarily reflect the opinions of my employer.

Upload: others

Post on 28-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

flickr.com/photos/djbiesack/85833076/

High Performance HTML5

stevesouders.com/docs/velocity-html5-20111207.pptx Disclaimer: This content does not necessarily reflect the opinions of my employer.

Page 2: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

flickr.com/photos/djbiesack/85833076/

High Performance HTML5

http://www.w3.org/TR/html5/

Page 3: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

drives traffic improves UX increases revenue reduces costs

flickr.com/photos/pedromourapinheiro/3123885534/

Web Performance Optimization

WPO

Page 4: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

Web Performance Working Group

chartered June 2010 Web Timing

•  Navigation Timing •  User Timing •  Resource Timing

Page Visibility Script-based animations Efficient script yielding http://www.w3.org/2010/webperf/

Page 5: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

flickr.com/photos/wwarby/3296379139/

Navigation Timing var timing = performance.timing; var loadtime = timing.loadEventEnd – timing.navigationStart;

Chrome 6+, IE9+, Firefox 7+, Android 4+ http://blog.chromium.org/2010/07/do-you-know-how-slow-

your-web-page-is.html

Page 6: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 7: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

on by default browsers that support Nav Timing

Chrome 6+ IE9+ Firefox 7+ (buggy) Android 4+

1% sampling rate by default can change to 10% _setSiteSpeedSampleRate()

http://analytics.blogspot.com/2011/11/site-speed-now-even-easier-to-access.html

GA site speed

Page 8: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

flickr.com/photos/juditk/5024772809/

Resource Timing •  DNS, redirects, etc. •  security safeguards

User Timing •  for web apps •  mark, measure

Page 9: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

flickr.com/photos/96221617@N00/51603550/

Page Visibility detect when page is visible

• stats • video & audio • polling, DHTML • performance: prefetching, prerendering

Chrome 13: • document.webkitHidden • webkitvisibilitychange

code.google.com/chrome/whitepapers/pagevisibility.html

Page 10: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

script async & defer script src

halts parsing, blocks rendering

async execute once script is downloaded

defer execute after page is parsed

missing download & execute last download last, execute on demand

flickr.com/photos/gevertulley/4771808965/

Page 11: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

GMail Mobile <script type="text/javascript"> /* var ... */ </script>

get script DOM element's text remove comments eval() when invoked awesome for prefetching JS that might

(not) be needed http://goo.gl/l5ZLQ

Page 12: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

ControlJS a JavaScript module for making scripts load faster

just change HTML

inline & external scripts

<script type="text/cjs" data-cjssrc="main.js"> </script>

<script type="text/cjs"> var name = getName(); </script>

Page 13: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

ControlJS a JavaScript module for making scripts load faster

download without executing <script type="text/cjs" data-cjssrc="main.js” data-cjsexec=false> <script>

Later if/when needed: CJS.execScript(src);

Page 14: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

app cache offline apps, longer cache

flickr.com/photos/india-nepal-iran/203982474/

Page 15: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

yuiblog.com/blog/2007/01/04/performance-research-part-2/

Page 16: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

blaze.io/mobile/understanding-mobile-cache-sizes/

Page 17: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

Home screen apps on iPhone are slower because resources are re-requested even though they should be read from cache.

Page 18: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

app cache offline apps, longer cache <!doctype html> <html manifest=“myapp.appcache”>

myapp.appcache:

flickr.com/photos/india-nepal-iran/203982474/

CACHE MANIFEST # Revision: 1.28

CACHE: /images/logo.gif

NETWORK: /login.html

FALLBACK: /index.html /offline.html Content-Type: text/cache-manifest

Page 19: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

app cache gotchas html docs w/ manifest are cached

404 => nothing is cached

size: 5MB+

must rev manifest to update resources

update is served on 2nd reload (?!?!)

flickr.com/photos/97657657@N00/1918688483/

Page 20: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

push app logo.gif =

user loads app app cache is empty

fetch manifest

fetch logo.gif

app cache =

user sees

push app logo.gif =

rev manifest

user loads app app cache =

user sees

fetch manifest

fetch logo.gif

app cache =

user loads app again app cache =

user sees

fetch manifest (304)

app cache reload

Page 21: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

flickr.com/photos/presley_m/5152304885/

window.applicationCache.addEventListener('updateready',

function(e) { if ( window.applicationCache.status ==

window.applicationCache.UPDATEREADY) {

if ( confirm(“Load new content?”) ) { ...

http://www.webdirections.org/blog/get-offline/

http://www.html5rocks.com/en/tutorials/appcache/beginner/

load twice workaround

Page 22: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

localStorage window.localStorage:

setItem() getItem() removeItem() clear()

also sessionStorage

all popular browsers, 5MB max http://dev.w3.org/html5/webstorage/ http://diveintohtml5.org/storage.html

flickr.com/photos/bryanpearson/564703455/

Page 23: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

localStorage as cache 1st doc: write JS & CSS blocks to localStorage

mres.-0yDUQJ03U8Hjija: <script>(function(){...

set cookie with entries & version MRES=-0yDUQJ03U8Hjija:-4EaJoFuDoX0iloI:...

later docs: read JS & CSS from localStorage document.write( localStorage.getItem(mres.-0yDUQJ03U8Hjija) );

http://stevesouders.com/blog/2011/03/28/storager-case-study-bing-google/

flickr.com/photos/nelsoncruz/431244400/

Page 24: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 25: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 26: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 27: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 28: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 29: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 30: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 31: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 32: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 33: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 34: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

flickr.com/photos/typoatelier/4261455105/

@font-face

stevesouders.com/blog/2010/06/01/frontend-spof/

Worth delaying most important design elements? Or entire page?

* IE9 does not display a blank page, but does “flash” the element.

Page 35: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

flickr.com/photos/imbrettjackson/520656349/

Page 36: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

improving @font-face smaller, custom font files avoid FOUT, impatient fallback

• n milliseconds • DOM loaded, window onload • user interaction

higher priority caching aggressively use expired fonts today: localStorage

flickr.com/photos/firebrat/2711165108/

Page 37: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

there’s more CSS instead of images: border radius,

linear & radial gradients, drop shadow SVG, inline SVG, and canvas video tag WebSockets web workers builtin controls: progress, datetime

flickr.com/photos/dualphoto/2609096047/

Page 38: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

and more history – http://www.kylescholz.com/blog/

2010/04/html5_history_is_the_future.html <a ping requestAnimationFrame – not timers native JSON parse/stringify

http://bit.ly/browserscope-modernizr

http://www.html5rocks.com/

flickr.com/photos/kaptainkobold/5741327207/

Page 39: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

Thanks to…

Max Firtman Tony Gentilcore Josh Fraser Kyle Scholz Stoyan Stefanov James Pearce

flickr.com/photos/robertvega/3944132320/

Lindsey Simon Annie Sullivan Tim Kadlec Paul Irish Jason Grigsby Brad Neuberg

Page 40: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

more stuff

flickr.com/photos/markdodds/399252797/

Page 41: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

developers.google.com/pagespeed/?velocity=1

Page 42: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 43: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 44: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 45: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 46: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 47: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty
Page 48: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

Top 100

Top 1000

Page 49: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

speed matters WPWG window.performance async & defer app cache, localStorage ! @font-face

takeaways

flickr.com/photos/myklroventine/4062102754/

Page 50: High Performance HTML5 - O'Reilly Velocity China 2016 Web ...velocity.oreilly.com.cn/2011/ppts/velocity-html5-20111207.pdf · push app logo.gif = user loads app app cache is empty

Steve Souders @souders

http://stevesouders.com/docs/velocity-html5-20111207.pptx