hacking web performance @ forwardjs 2017

95
Picture from Simon Howden freedigitalphotos.net hacking web performance Max Firtman @firt

Upload: maximiliano-firtman

Post on 12-Apr-2017

507 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Hacking Web Performance @ ForwardJS 2017

Picture from Simon Howden freedigitalphotos.net!

Picture from Simon Howden freedigitalphotos.net!

hacking web performance

Max Firtman @firt

Page 2: Hacking Web Performance @ ForwardJS 2017

mobile+web developer & trainer

Page 3: Hacking Web Performance @ ForwardJS 2017

😬

Page 4: Hacking Web Performance @ ForwardJS 2017
Page 5: Hacking Web Performance @ ForwardJS 2017
Page 6: Hacking Web Performance @ ForwardJS 2017
Page 7: Hacking Web Performance @ ForwardJS 2017

I have 2 goals…

Page 8: Hacking Web Performance @ ForwardJS 2017

Show you new tricks 😁

Page 9: Hacking Web Performance @ ForwardJS 2017

Make you feel bad

Page 10: Hacking Web Performance @ ForwardJS 2017

Let’s Start!

Page 11: Hacking Web Performance @ ForwardJS 2017

I know you know

Page 12: Hacking Web Performance @ ForwardJS 2017

http://www.flickr.com/photos/steenslag/22689920/-borrowedfromSteveSouders

Page 13: Hacking Web Performance @ ForwardJS 2017

Picture from Simon Howden freedigitalphotos.net

Page 14: Hacking Web Performance @ ForwardJS 2017

14

Picture from Simon Howden freedigitalphotos.net

Page 15: Hacking Web Performance @ ForwardJS 2017

500ms delay, +26% user’s frustration

Source: Radware

:(

Page 16: Hacking Web Performance @ ForwardJS 2017

500ms delay, -20% Google’s traffic

1http://home.blarg.net/~glinden/StanfordDataMining.2006-11-29.ppt

:(

Page 17: Hacking Web Performance @ ForwardJS 2017

+100ms delay, -1% Amazon’s sales

1http://home.blarg.net/~glinden/StanfordDataMining.2006-11-29.ppt

:(

Page 18: Hacking Web Performance @ ForwardJS 2017

immediate feedback 100ms

perception

Jakob Nielsen - Usability Engineering

Page 19: Hacking Web Performance @ ForwardJS 2017

perception

Jakob Nielsen - Usability Engineering

losing flow of thoughts 1s

Page 20: Hacking Web Performance @ ForwardJS 2017

perception

Source: Google Developers

RAIL

Page 21: Hacking Web Performance @ ForwardJS 2017

perception

RAIL

100ms

Page 22: Hacking Web Performance @ ForwardJS 2017

perception

RAIL

100ms 16ms

Page 23: Hacking Web Performance @ ForwardJS 2017

perception

RAIL

100ms 16ms 50ms

Page 24: Hacking Web Performance @ ForwardJS 2017

perception

RAIL

100ms 16ms 50ms 1s

Page 25: Hacking Web Performance @ ForwardJS 2017
Page 26: Hacking Web Performance @ ForwardJS 2017

I know you know

Performance is important We need a great Speed Index We have a budget of 1 second to load

Page 27: Hacking Web Performance @ ForwardJS 2017

You are already…

Page 28: Hacking Web Performance @ ForwardJS 2017

Optimizing the network

You are already

Page 29: Hacking Web Performance @ ForwardJS 2017

CSS as Appetizer

You are already

Page 30: Hacking Web Performance @ ForwardJS 2017

JavaScript as Dessert

You are already

Page 31: Hacking Web Performance @ ForwardJS 2017

Optimizing Images

You are already

Page 32: Hacking Web Performance @ ForwardJS 2017

Have an HTTP Cache Policy

You are already

Page 33: Hacking Web Performance @ ForwardJS 2017

Using Service Workers

You are already

Page 34: Hacking Web Performance @ ForwardJS 2017

Avoiding Redirects

You are already

Page 35: Hacking Web Performance @ ForwardJS 2017

Working with TLS and HTTP/2

You are already

Page 36: Hacking Web Performance @ ForwardJS 2017

You are already doing this

Page 37: Hacking Web Performance @ ForwardJS 2017

What’s the problem then?

Page 38: Hacking Web Performance @ ForwardJS 2017

Average time to load a mobile landing page

The problem

22 seconds Research by thinkwithgoogle.com

Page 39: Hacking Web Performance @ ForwardJS 2017

If a page takes more than 3 seconds to load

The problem

53% leave it Research by thinkwithgoogle.com

Page 40: Hacking Web Performance @ ForwardJS 2017

The problem

Page 41: Hacking Web Performance @ ForwardJS 2017

The problem

AMP Facebook Instant Articles

Page 42: Hacking Web Performance @ ForwardJS 2017

The problem

We always underestimate

mobile

Page 43: Hacking Web Performance @ ForwardJS 2017

iOS and Android

Page 44: Hacking Web Performance @ ForwardJS 2017

Safari and Chrome?

Page 45: Hacking Web Performance @ ForwardJS 2017

Source: MOVR Report

Page 46: Hacking Web Performance @ ForwardJS 2017

browsers with market share

Page 47: Hacking Web Performance @ ForwardJS 2017

Using Cellular Networks!

Page 48: Hacking Web Performance @ ForwardJS 2017

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

(

)

Page 49: Hacking Web Performance @ ForwardJS 2017

cellular

0

25

50

75

100

US Western Europe Asia Global

4G 2G/3G

Only 21% is on 4G, worldwide

Page 50: Hacking Web Performance @ ForwardJS 2017

cellular

Page 51: Hacking Web Performance @ ForwardJS 2017

cellular

45% of users are on 2G networks

Page 52: Hacking Web Performance @ ForwardJS 2017

cellular

0

25

50

75

100

US Western Europe Asia Global

4G 2G/3G

~30% of the time 4G was not used

Page 53: Hacking Web Performance @ ForwardJS 2017

RTT - latencycellular networks

2G

3G

4G

Home

0 250 500 750 1000

Min Max

Page 54: Hacking Web Performance @ ForwardJS 2017

Let’s hack Web Performance!

Page 55: Hacking Web Performance @ ForwardJS 2017

Hack First Load

Page 56: Hacking Web Performance @ ForwardJS 2017

Avoid more than one roundtrip

First Load

Page 57: Hacking Web Performance @ ForwardJS 2017

Deliver ATF in 14Kb

First Load

• Embed all CSS and JavaScript needed • If space, embed logo and/or low-res images

Page 58: Hacking Web Performance @ ForwardJS 2017

Announce DNS queries ASAP

First Load

<link rel="dns-prefetch" href="http://newdomain.com">

HTML

Page 59: Hacking Web Performance @ ForwardJS 2017

Avoid http to httpS redirect

First Load

• Use HSTS (HTTP Strict Transport Security) • Header • Opt-in at hstspreload.org

Page 60: Hacking Web Performance @ ForwardJS 2017

Hack Data Transfer

Page 61: Hacking Web Performance @ ForwardJS 2017

Use Zopfli

Data Transfer

• Save 4-8% data transfer with GZIP • It’s ~80x slower

Page 62: Hacking Web Performance @ ForwardJS 2017

Use Brotli

Data Transfer

• Save ~14% data transfer • Check Encoding Header

Page 63: Hacking Web Performance @ ForwardJS 2017

Create a low-res version

Data Transfer

• Check save-data Client Hint header • Use NetInfo API • Use Performance Timing API • Measure bandwidth

Page 64: Hacking Web Performance @ ForwardJS 2017
Page 65: Hacking Web Performance @ ForwardJS 2017

Embrace Responsive Images

Data Transfer

• Not just 3 versions of your image • 65% of the traffic is for images (HttpArchive)

• 84% improvement creating n versions (ScientiaMobile)

Page 66: Hacking Web Performance @ ForwardJS 2017

Hack Images

Page 67: Hacking Web Performance @ ForwardJS 2017

http://www.flickr.com/photos/steenslag/22689920/-borrowedfromSteveSouders

A picture is worth a thousand words…

Page 68: Hacking Web Performance @ ForwardJS 2017

… if it loads

Page 69: Hacking Web Performance @ ForwardJS 2017

Time to replace JPEG and PNG

Images

Page 70: Hacking Web Performance @ ForwardJS 2017
Page 71: Hacking Web Performance @ ForwardJS 2017

Lossy format: WebP -35%

Images

Page 72: Hacking Web Performance @ ForwardJS 2017

Lossy format: JPEG 2000 (JPX) -19%

Images

Page 73: Hacking Web Performance @ ForwardJS 2017

Lossy format: JPEG XR (JXR) -29%

Images

Page 74: Hacking Web Performance @ ForwardJS 2017

Lossless format: Zopfli PNG

https://github.com/imagemin/zopflipng-bin

-20%

Images

Page 75: Hacking Web Performance @ ForwardJS 2017

Deal with compatibility!

Images

• Hello to <picture>

Page 76: Hacking Web Performance @ ForwardJS 2017

<picture>

<source type="image/webp" src="image.webp"><source type="image/vnd.ms-photo" src="image.jxr"><source type="image/jp2" src="image.jp2"><source type="image/png" src=“image.zf.png"><img src=“image.zf.png" alt=“description">

</picture>

Page 77: Hacking Web Performance @ ForwardJS 2017

Meet HTTP Client Hints

Images

• Browser will expose data to the server<meta http-equiv="Accept-CH" content="DPR, Viewport-Width, Downlink">

HTML

Page 78: Hacking Web Performance @ ForwardJS 2017

Decode images in the background

Images

• github.com/GoogleChrome/offthread-image

Page 79: Hacking Web Performance @ ForwardJS 2017

Stop using Animated GIFs!

Images

• Use Animated PNGs or Animated WebP • Use muted videos • Use webkit-playsinline for iOS

Page 80: Hacking Web Performance @ ForwardJS 2017

Use tricks for Preview Images

Images

Page 81: Hacking Web Performance @ ForwardJS 2017
Page 82: Hacking Web Performance @ ForwardJS 2017

Images

Page 83: Hacking Web Performance @ ForwardJS 2017

The future looks interesting!

Images

• BPG • FLIF

Page 84: Hacking Web Performance @ ForwardJS 2017

Hack Limitsthanks to Service Workers

Page 85: Hacking Web Performance @ ForwardJS 2017

Make CDNs race for performance

Limits

Page 86: Hacking Web Performance @ ForwardJS 2017

Delta Updates

Limits

Page 87: Hacking Web Performance @ ForwardJS 2017

Use Streams

Limits

Page 88: Hacking Web Performance @ ForwardJS 2017

Your own Compression Method

Limits

Page 89: Hacking Web Performance @ ForwardJS 2017

Progressive Images

Limits

Page 90: Hacking Web Performance @ ForwardJS 2017

Use BPG Today!

Limits

https://github.com/sandropaganotti/bpg-converter

Page 91: Hacking Web Performance @ ForwardJS 2017
Page 92: Hacking Web Performance @ ForwardJS 2017

Feeling bad enough?

Page 93: Hacking Web Performance @ ForwardJS 2017

Performance is TOP PRIORITY Push it even more It’s a worthwhile effort

Page 94: Hacking Web Performance @ ForwardJS 2017

Make it fast!

Page 95: Hacking Web Performance @ ForwardJS 2017

Foto de freefoto.com

[email protected]@firt

firt.mobi/hpmw

Next Forward workshopsProgressive Web AppsNew Web APIs Lab: VR, BT, PaymentsApps with TypeScript and Angular