169
Picture from Simon Howden freedigitalphotos.net extreme web performance for mobile devices maximiliano @rtman rt.mobi Amsterdam, Oct 28 2015

Extreme Web Performance for Mobile Devices

Embed Size (px)

Citation preview

Page 1: Extreme Web Performance for Mobile Devices

Picture from Simon Howden freedigitalphotos.net!

extreme web performance for mobile devices

maximiliano @firtman firt.mobi

Amsterdam, Oct 28 2015

Page 2: Extreme Web Performance for Mobile Devices
Page 3: Extreme Web Performance for Mobile Devices

EARLY DRAFT!

Page 4: Extreme Web Performance for Mobile Devices
Page 5: Extreme Web Performance for Mobile Devices

Slides, links and tests firtman.github.io/velocity

Page 6: Extreme Web Performance for Mobile Devices

questions

yes, please

QA at the end

Page 7: Extreme Web Performance for Mobile Devices

performance + mobile + web

1- Mobile Web today 2- Performance & Mobile 3- Tools 4- APIs & Specs 5- 8 Tips for Extreme Performance

Page 8: Extreme Web Performance for Mobile Devices
Page 9: Extreme Web Performance for Mobile Devices

1- mobile web today*

*today: october 2015

Page 10: Extreme Web Performance for Mobile Devices

1- mobile web today- Web Platforms - The Android’s problem - The WebView’s problem

Page 11: Extreme Web Performance for Mobile Devices

web platforms

Page 12: Extreme Web Performance for Mobile Devices

iOS and Android

web platforms

Page 13: Extreme Web Performance for Mobile Devices

NetMarketShare Akamai.io Wikimedia Stats StatCounter MOVR by WURFL Device Atlas

web platformsLinks at firtman,github.io/velocity

Page 14: Extreme Web Performance for Mobile Devices

Browsers only?

web platforms

Page 15: Extreme Web Performance for Mobile Devices
Page 16: Extreme Web Performance for Mobile Devices
Page 17: Extreme Web Performance for Mobile Devices

web view browsing

Web View25%

Browser75%

Other 30%

Twitter 5% Facebook

40%

Chrome (iOS) 25%

Source: MOVR Report

Page 18: Extreme Web Performance for Mobile Devices

Let’s see some data

web platforms

Page 19: Extreme Web Performance for Mobile Devices

web platformsOthers 10%

iOS45%

Android45%

Page 20: Extreme Web Performance for Mobile Devices

web platformsOthers 10%

iOS45%

Android45%

Page 21: Extreme Web Performance for Mobile Devices

web platforms

iOS45%

Safari100% ?

Page 22: Extreme Web Performance for Mobile Devices

web platforms

Apps (WebView) 25%

Safari75%

iOS45%

Page 23: Extreme Web Performance for Mobile Devices

web platforms

7.x 9%

8.x30% 9.x

61%

Source: Apple

iOS45%

Page 24: Extreme Web Performance for Mobile Devices

web platformsOthers 10%

iOS45%

Android45%

Page 25: Extreme Web Performance for Mobile Devices

web platforms

Android45%

Page 26: Extreme Web Performance for Mobile Devices

web platforms

Browser33%

Chrome67%

Android45%

Page 27: Extreme Web Performance for Mobile Devices
Page 28: Extreme Web Performance for Mobile Devices

1% month

Page 29: Extreme Web Performance for Mobile Devices
Page 30: Extreme Web Performance for Mobile Devices

web platforms

Page 31: Extreme Web Performance for Mobile Devices

web platforms

Page 32: Extreme Web Performance for Mobile Devices

web platforms

Page 33: Extreme Web Performance for Mobile Devices

LG G3

Page 34: Extreme Web Performance for Mobile Devices

web platforms

Browser 2.x 3%

Samsung17%

Browser 4.x30%

Chrome50%

Android45%

Page 35: Extreme Web Performance for Mobile Devices

web platformsOthers 10%

iOS45%

Android45%

Page 36: Extreme Web Performance for Mobile Devices

web platformsOthers 10%

Page 37: Extreme Web Performance for Mobile Devices

web platformsOthers 10%

Others 15%

Firefox 10%

UC Browser 25%

IE 25%

Opera Mini 25%

Page 38: Extreme Web Performance for Mobile Devices

web platformsOthers 10%

iOS45%

Android45%

Page 39: Extreme Web Performance for Mobile Devices

web platforms

Android15%

Samsung7%

Others2%

Windows Phone3%

UC Browser 3%

Opera 3%

InApp iOS12%

Safari iOS810%

Safari iOS923%

Chrome23%

Page 40: Extreme Web Performance for Mobile Devices

web platforms

Old WebKit14%

IE3%

Proxy5%

WebKit46%

Chromium30%

Page 41: Extreme Web Performance for Mobile Devices

1- mobile web today

- Understand the real ecosystem - The Android browsers - The WebView - Don’t think you are an average user

Page 42: Extreme Web Performance for Mobile Devices

2- mobile & performance

- Perception - Differences - Cellular networks - Responsive Web Design

Page 43: Extreme Web Performance for Mobile Devices

immediate feedback 100ms

perception

Jakob Nielsen - Usability Engineering

Page 44: Extreme Web Performance for Mobile Devices

immediate feedback 100ms

losing user’s flow of thoughts 1s

perception

Jakob Nielsen - Usability Engineering

Page 45: Extreme Web Performance for Mobile Devices

500ms delay, +26% user’s frustration

perception

Source: Radware

Page 46: Extreme Web Performance for Mobile Devices

40% of users abandon an article if it doesn't load after six seconds

”Danny Bernstein, Google

Page 47: Extreme Web Performance for Mobile Devices

Pages loaded 3.9x faster with Crystal and used 53% less bandwidth

”Crystal, an iOS ad-blocker

Page 48: Extreme Web Performance for Mobile Devices

perception

Source: Google Developers

RAIL

Page 49: Extreme Web Performance for Mobile Devices

perception

RAIL

100ms

Page 50: Extreme Web Performance for Mobile Devices

perception

RAIL

100ms 16ms

Page 51: Extreme Web Performance for Mobile Devices

perception

RAIL

100ms 16ms 50ms

Page 52: Extreme Web Performance for Mobile Devices

perception

RAIL

100ms 16ms 50ms 1s

Page 53: Extreme Web Performance for Mobile Devices

why do we need special care on mobile?

Page 54: Extreme Web Performance for Mobile Devices

Cellular connections

differences

Page 55: Extreme Web Performance for Mobile Devices

We have 4G! We don't need to worry about performance...

(

)

Page 56: Extreme Web Performance for Mobile Devices

cellular

0

25

50

75

100

US Western Europe Asia Global

4G 2G/3G

Only 10% is on 4G globally

Page 57: Extreme Web Performance for Mobile Devices

cellular

0

25

50

75

100

US Western Europe Asia Global

4G 2G/3G

~30% of the time 4G was not used

Page 58: Extreme Web Performance for Mobile Devices

Real Bandwidth (Mbps)cellular networks

0 3.5 7 10.5 14

2G 3G Wifi 4G

Page 59: Extreme Web Performance for Mobile Devices

RTT - latencycellular networks

2G

3G

4G

Home

0 250 500 750 1000

Min Max

Page 60: Extreme Web Performance for Mobile Devices

latency

request

bandwidth

Page 61: Extreme Web Performance for Mobile Devices

Safari, Chrome, Android 88%93%

Page 62: Extreme Web Performance for Mobile Devices

1%

5%

4%

Other non-Android, non-iOS 6%

Safari, Chrome, Android 88%94%

Page 63: Extreme Web Performance for Mobile Devices

responsive web design

Page 64: Extreme Web Performance for Mobile Devices
Page 65: Extreme Web Performance for Mobile Devices

Responsive Web Design is a TOOL

Page 66: Extreme Web Performance for Mobile Devices

Responsive Web Design is NOT a GOAL

Page 67: Extreme Web Performance for Mobile Devices

Users DON’T care if your site is RESPONSIVE

(in terms of RWD)

Page 68: Extreme Web Performance for Mobile Devices

Users DO care if the site is FAST

Page 69: Extreme Web Performance for Mobile Devices

Wait there! Google said it will penalize non-responsive sites…

(

)

Page 70: Extreme Web Performance for Mobile Devices

Mmm…. NOT REALLY

Page 71: Extreme Web Performance for Mobile Devices
Page 72: Extreme Web Performance for Mobile Devices

2- mobile and performance- Perception: RAIL, 100ms / 1s - RTT latency - RWD as a goal might be a problem - Test on low hardware and 2G/3G

Page 73: Extreme Web Performance for Mobile Devices

3- tools

Page 74: Extreme Web Performance for Mobile Devices

3- tools- where - measuring loading times - measuring responsiveness - online tools - html5 apis

Page 75: Extreme Web Performance for Mobile Devices

Simulator & Emulator

Real device

where

Page 76: Extreme Web Performance for Mobile Devices

emulators

Android14%

Samsung7%

Others2%

Windows Phone3%

UC Browser 3%

Opera 3%

InApp iOS14%

Safari iOS810%

Safari iOS922%

Chrome23%

Page 77: Extreme Web Performance for Mobile Devices

emulators

Android14%

Samsung7%

Others2%

Windows Phone3%

UC Browser 3%

Opera3%

InApp iOS14%

Safari iOS810%

Safari iOS922%

Chrome23%

Page 78: Extreme Web Performance for Mobile Devices

DEMO

Page 79: Extreme Web Performance for Mobile Devices

online tools

Page 80: Extreme Web Performance for Mobile Devices

online tools

Page 81: Extreme Web Performance for Mobile Devices

online tools

Page 82: Extreme Web Performance for Mobile Devices

online tools

Page 83: Extreme Web Performance for Mobile Devices

remote inspectors

Page 84: Extreme Web Performance for Mobile Devices

remote inspectors

Android14%

Samsung7%

Others2%

Windows Phone3%

UC Browser 3%

Opera 3%

InApp iOS14%

Safari iOS810%

Safari iOS922%

Chrome23%

Page 85: Extreme Web Performance for Mobile Devices

Measuring

DEMO

Page 86: Extreme Web Performance for Mobile Devices

Proxies / Network sniffers

• Charles Proxy • Fiddler

tools

Image from telerik fiddler

Page 87: Extreme Web Performance for Mobile Devices

Connection simulators

• Network link conditioner (Mac/iOS) • Charles Proxy • Clumsy for Windows • Net Limiter for Windows • SlowyApp for Mac • Chrome Developer Tools

tools

Page 88: Extreme Web Performance for Mobile Devices

3- tools

- Learn where to test - Measure loading times - Measure responsiveness

Page 89: Extreme Web Performance for Mobile Devices

4- apis & specsfor performance

Page 90: Extreme Web Performance for Mobile Devices

Navigation Timing API

• window.performance • Timestamps available

html5 apis

Page 91: Extreme Web Performance for Mobile Devices

navigation timing api

* Android browser only from 4.0

Android14%

Samsung7%

Others2%

Windows Phone3%

UC Browser 3%

Opera 3%

InApp iOS14%

Safari iOS810%

Safari iOS922%

Chrome23%

Page 92: Extreme Web Performance for Mobile Devices

Navigation Timing APIhtml5 apis

DEMO

Page 93: Extreme Web Performance for Mobile Devices

Resource Timing API

• Information per resource

html5 apis

Page 94: Extreme Web Performance for Mobile Devices

resource timing

Android14%

Samsung7%

Others2%

Windows Phone3%

UC Browser 3%

Opera 3%

InApp iOS14%

Safari iOS810%

Safari iOS922%

Chrome23%

Page 95: Extreme Web Performance for Mobile Devices

Network information API

• Android Browser, Silk (spec #1) type • BlackBerry 10 (spec #2) bandwidth • Firefox, Chrome 38+ (spec #3) type & events • Chrome 47+ (spec #4) type & estimated bw

html5 apis

Page 96: Extreme Web Performance for Mobile Devices

net info api

* Different specs available

Android14%

Samsung7%

Others2%

Windows Phone3%

UC Browser 3%

Opera 3%

InApp iOS14%

Safari iOS810%

Safari iOS922%

Chrome23%

Page 97: Extreme Web Performance for Mobile Devices

Service Workers

• Manage offline cache • Background sync • Push Notifications

html5 apis

Page 98: Extreme Web Performance for Mobile Devices

service workers

Android14%

Samsung7%

Others2%

Windows Phone3%

UC Browser 3%

Opera 3%

InApp iOS14%

Safari iOS810%

Safari iOS922%

Chrome23%

Page 99: Extreme Web Performance for Mobile Devices

Request Idle Callback

• Do something when the browser is idle • Chrome 47+ (beta today)

html5 apis

Page 100: Extreme Web Performance for Mobile Devices

HTTP Client Hints

• HTTP Headers: dpr, viewport’s width • Chrome 46+ • New: save-data (future)

html5 apis

Page 101: Extreme Web Performance for Mobile Devices

HTTP/2

• Performance from scratch • Header Compression • TCP connection reuse • Push to Cache • Early tests show 15-60% load time improvement

Page 102: Extreme Web Performance for Mobile Devices

HTTP/2

• TLS-based only today • Good compatibility • Upgrade your servers • Upgrade connections

Page 103: Extreme Web Performance for Mobile Devices

http/2

Android14%

Samsung7%

Others2%

Windows Phone3%

UC Browser 3%

Opera 3%

InApp iOS14%

Safari iOS810%

Safari iOS922%

Chrome23%

Page 104: Extreme Web Performance for Mobile Devices
Page 105: Extreme Web Performance for Mobile Devices

AMP-HTML

Page 106: Extreme Web Performance for Mobile Devices
Page 107: Extreme Web Performance for Mobile Devices

4- apis & specs

- HTML5 APIs - Look for the near future - HTTP/2 when possible- AMP new idea

Page 108: Extreme Web Performance for Mobile Devices

5- Extreme Performance Tips

Page 109: Extreme Web Performance for Mobile Devices

Network Layer Stop Signs RWD as a goal HTML in 14k

CSS ASAP JavaScript as dessert Fast UI Web Views

Page 110: Extreme Web Performance for Mobile Devices
Page 111: Extreme Web Performance for Mobile Devices
Page 112: Extreme Web Performance for Mobile Devices
Page 113: Extreme Web Performance for Mobile Devices
Page 114: Extreme Web Performance for Mobile Devices

Image from developers.google.com

Page 115: Extreme Web Performance for Mobile Devices
Page 116: Extreme Web Performance for Mobile Devices

What!!? Do you expect a page load in 200ms?

(

)

Page 117: Extreme Web Performance for Mobile Devices

No really, we just need the PERCEPTION

Page 118: Extreme Web Performance for Mobile Devices

Network Layer

Page 119: Extreme Web Performance for Mobile Devices

Network Layer

• Reduce DNS and HTTP requests • Domain Sharding • Gzip responses • 14Kb congestion window for achieve 1s

Page 120: Extreme Web Performance for Mobile Devices

Network Layer

• Reduce DNS and HTTP requests • Domain Sharding • Gzip responses • 14Kb congestion window for achieve 1s

HTTP/2

HTTP/2

HTTP/2

HTTP/2

Page 121: Extreme Web Performance for Mobile Devices

Stop Signs

Page 122: Extreme Web Performance for Mobile Devices

REDIRECTS

Page 123: Extreme Web Performance for Mobile Devices

APP BANNER

Page 124: Extreme Web Performance for Mobile Devices

CLIENT RENDERING

Page 125: Extreme Web Performance for Mobile Devices

Stop Signs

• Reduce redirects (100ms to 1s each) (social networks have one or two) • Don’t create custom app banners • Don’t use client side rendering for first view

Page 126: Extreme Web Performance for Mobile Devices

Stop Signs

• Reduce redirects (100ms to 1s each) (social networks have one or two) • Don’t create custom app banners • Don’t use client side rendering for first view

HTTP/2

HTTP/2HTTP/2

Page 127: Extreme Web Performance for Mobile Devices

RWD as a Goal

Page 128: Extreme Web Performance for Mobile Devices

RESPONSIVE WEB DESIGN is the future

Page 129: Extreme Web Performance for Mobile Devices

We are not saying go m.*

Page 130: Extreme Web Performance for Mobile Devices

Responsive Web Design

• Using same URL still a good a idea • Mix it with RESS / adaptive web design • Load media queries CSS async • Use server-side libraries • WURFL or DeviceAtlas

Page 131: Extreme Web Performance for Mobile Devices

But we are front-end!

Page 132: Extreme Web Performance for Mobile Devices

Time to rethink priorities and architecture

Server

Client Frontend engineer

Backend engineer

Page 133: Extreme Web Performance for Mobile Devices

Server

Client Frontend engineer

Backend engineer

Frontend server

Page 134: Extreme Web Performance for Mobile Devices

HTML in 14Kb

Page 135: Extreme Web Performance for Mobile Devices

• ATF in 1s = 1 RTT ~ < 14Kb (compressed) • > 14Kb will create another roundtrip • HTML + CSS + JavaScript • Images?

Page 136: Extreme Web Performance for Mobile Devices

We need to separate ABOVE THE FOLD (ATF)

content

Page 137: Extreme Web Performance for Mobile Devices

Distract the user

Page 138: Extreme Web Performance for Mobile Devices

HTML in 14Kb

• ATF content in 14Kb • Create an AMP-HTML version if applicable • Speed future visits • HD/SD contexts

Page 139: Extreme Web Performance for Mobile Devices

HTML in 14Kb

• ATF content in 14Kb • Create an AMP-HTML version if applicable • Speed future visits • HD/SD contexts

HTTP/2HTTP/2

HTTP/2HTTP/2

Page 140: Extreme Web Performance for Mobile Devices

Immediate feedback

• The 300ms delay

• mobile viewport (“user-scalable=no” on some browsers) • FastClick solution

Page 141: Extreme Web Performance for Mobile Devices

Immediate feedback

• Mobile Viewport on Chrome

<meta name=viewport content="width=device-width">

HTML

Page 142: Extreme Web Performance for Mobile Devices

Immediate feedback

• Mobile Fixed Viewport on IE <meta name=viewport content="width=device-width, user-scalable=no" >

HTML

Page 143: Extreme Web Performance for Mobile Devices

Immediate feedback

• CSS on IE html { -ms-touch-action: manipulation; touch-action: manipulation; }

CSS

Page 144: Extreme Web Performance for Mobile Devices

CSS ASAP

Page 145: Extreme Web Performance for Mobile Devices

Basic browser behavior

HTML

JS CSS

Page 146: Extreme Web Performance for Mobile Devices

Basic browser behavior

HTML

JS CSSBLOCKS RENDERING

Page 147: Extreme Web Performance for Mobile Devices

CSS ASAP

• Don’t rely on media queries only • Inline ATF CSS • Load async the rest • Push them on HTTP/2 • Use only one CSS file

Page 148: Extreme Web Performance for Mobile Devices

CSS ASAP

• Don’t rely on media queries only • Inline ATF CSS • Load async the rest • Push them on HTTP/2 • Use only one CSS file

HTTP/2HTTP/2

HTTP/2

HTTP/2

HTTP/2

Page 149: Extreme Web Performance for Mobile Devices

JavaScript as dessert

Page 150: Extreme Web Performance for Mobile Devices

Basic browser behavior

HTML

JS CSSBLOCKS PARSING

Page 151: Extreme Web Performance for Mobile Devices

Avoid JavaScript frameworks

• Embrace Vanilla JS • Load it async • Join everything in one JS file • Keep 60fps frame rate consistent

JavaScript

Page 152: Extreme Web Performance for Mobile Devices

• Embrace Vanilla JS • Load it async • Join everything in one JS file • Keep 60fps frame rate consistent

Avoid JavaScript frameworksJavaScript

HTTP/2HTTP/2

HTTP/2

Page 153: Extreme Web Performance for Mobile Devices

Fast UI

Page 154: Extreme Web Performance for Mobile Devices

• Images are non-blocking by default • Don’t use Data URI => blocking • Responsive Images • Remember HD/SD • User SVG when possible • New Formats: WebP, APNG

Image and UI

Page 155: Extreme Web Performance for Mobile Devices

Your new enemy

Page 156: Extreme Web Performance for Mobile Devices

NOT THE USER

Page 157: Extreme Web Performance for Mobile Devices

YOUR DESIGNER

Page 158: Extreme Web Performance for Mobile Devices

Careful with some design features

• GPU vs CPU repaint • Important on scroll, transitions & animations

• Transforms and opacity GPU • border-radius, gradients, shadows, filters CPU repaint

Page 159: Extreme Web Performance for Mobile Devices

Web Views

Page 160: Extreme Web Performance for Mobile Devices

Web Views

• Too many on Android • WebKit, Chromium, Amazon, Samsung

• Two on iOS: old and new

Page 161: Extreme Web Performance for Mobile Devices

Web Views

• Less performant • Don’t share sessions with the browser • No HTTP/2 support on most of them

Page 162: Extreme Web Performance for Mobile Devices

Fast Web Views on Android

• Project Crosswalk for local content • Chrome Custom Tabs for browsing

Page 163: Extreme Web Performance for Mobile Devices

Fast Web Views on iOS

• Project Crosswalk for local content • WKWebView (iOS 9+) • Safari View Controller for browsing (iOS 9+)

Page 164: Extreme Web Performance for Mobile Devices

Picture from Simon Howden freedigitalphotos.net!

Picture from Simon Howden freedigitalphotos.net!

uf! we've covered a lot!

Page 165: Extreme Web Performance for Mobile Devices

Improve Network Avoid Stop Signs Avoid RWD as a goal HTML in 14k

CSS ASAP JavaScript as dessert Fast UI Fast Web Views

Page 166: Extreme Web Performance for Mobile Devices

1- Mobile Web today 2- Mobile Performance 3- Tools 4- New APIs & Specs 5- Extreme Performance Tips

Page 167: Extreme Web Performance for Mobile Devices

Slides, links and tests firtman.github.io/velocity

Page 168: Extreme Web Performance for Mobile Devices

final thoughts

- measure and profile on the real world - don’t redirect, reduce requests - atf content in 1s, defer the rest - be simple, be aggressive, be smart

Page 169: Extreme Web Performance for Mobile Devices

you can reach a good experience

Pictures)from)freedigitalphotos.net)

[email protected]@firt

firt.mobi/hpmw firt.mobi/mh5