responsive images and performance

63
Picture from Simon Howden freedigitalphotos.net responsive images & performance Maximiliano Firtman @firt

Upload: maximiliano-firtman

Post on 12-Apr-2017

310 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Responsive Images and Performance

Picture from Simon Howden freedigitalphotos.net!

Picture from Simon Howden freedigitalphotos.net!

responsive images &

performance

Maximiliano Firtman @firt

Page 2: Responsive Images and Performance

mobile+web developer & trainer

Page 3: Responsive Images and Performance

training

Page 4: Responsive Images and Performance
Page 5: Responsive Images and Performance
Page 6: Responsive Images and Performance
Page 7: Responsive Images and Performance

questions

yes, please

QA at the end

Page 8: Responsive Images and Performance

responsive images & performance

the problem new file formats http client hints what’s next

Page 9: Responsive Images and Performance

Let’s Start!

Page 10: Responsive Images and Performance

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

A picture is worth a thousand words…

Page 11: Responsive Images and Performance

… if it appears in time

Page 12: Responsive Images and Performance

What’s the problem with images on the Web?

Page 13: Responsive Images and Performance

Source: HTTP Archive

Page 14: Responsive Images and Performance

Mobile devices with high resolution

Page 15: Responsive Images and Performance

…higher than desktop screens

Page 16: Responsive Images and Performance

using cellular networks

Page 17: Responsive Images and Performance

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

(

)

Page 18: Responsive Images and Performance

cellular

0

25

50

75

100

US Western Europe Asia Global

4G 2G/3G

Only 21% is on 4G, worldwide

Page 19: Responsive Images and Performance

cellular

Page 20: Responsive Images and Performance

cellular

50% of users are on 2G networks

Page 21: Responsive Images and Performance

cellular

0

25

50

75

100

US Western Europe Asia Global

4G 2G/3G

~30% of the time 4G was not used

Page 22: Responsive Images and Performance

RTT - latencycellular networks

2G

3G

4G

Home

0 250 500 750 1000

Min Max

Page 23: Responsive Images and Performance

rendering images is expensive

Page 24: Responsive Images and Performance

Responsive Images are here to help

Page 25: Responsive Images and Performance

Responsive Images

• Provides with multiple image sources depending on: • display density • size of the image element in the page • image type

Page 26: Responsive Images and Performance
Page 27: Responsive Images and Performance

Responsive Images

• srcset (HTML) • image-set (CSS) • picture • server-side techniques (such as using WURFL)

Page 28: Responsive Images and Performance

<img src="photo.png" width="300" srcset="photo_lo.png 1x, photo_hi.png 2x, photo_uhi.png 3x">

Page 29: Responsive Images and Performance

<picture> <source media="(min-width: 300px)" src="hi.jpg"> <source media="(min-width: 600px)" src="mid.jpg"> <source src="lo.jpg"> <img src="fallback.jpg" alt=""> </picture>

Page 30: Responsive Images and Performance

Responsive Images

• The browser will pick the best image • We won’t send pixels that will never be rendered

Page 31: Responsive Images and Performance

Is that all?

(

)

Page 32: Responsive Images and Performance

No, we need to push images further in performance

(

)

Page 33: Responsive Images and Performance

Image Formats

Page 34: Responsive Images and Performance

Image Formats

• Pick the right one for each situation (JPEG, GIF, PNG, SVG) • Optimize the file with tools

Page 35: Responsive Images and Performance
Page 36: Responsive Images and Performance

Lossless format: PNG

• iPhone 7+ • Desktop

3Mb 1.5Mb

Page 37: Responsive Images and Performance

Lossless format: Zopfli PNG

• iPhone 7+ • Desktop

2.3Mb 1.2Mb

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

-20%

Page 38: Responsive Images and Performance

Lossy format: JPEG

• iPhone 7+ • Desktop

927Kb 300Kb

90% compression

Page 39: Responsive Images and Performance

Lossy format: JPEG 2000 (JPX)

• iPhone 7+ • Desktop

752Kb 221Kb

90% compression

-19%

Page 40: Responsive Images and Performance

Lossy format: JPEG XR (JXR)

• iPhone 7+ • Desktop

665Kb 217Kb

90% compression

-29%

Page 41: Responsive Images and Performance

Lossless/Lossy format: WebP

• iPhone 7+ • Desktop

402Kb 213Kb

90% compression

-35%

Page 42: Responsive Images and Performance

How to serve multiple formats?

Page 43: Responsive Images and Performance

<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 44: Responsive Images and Performance

Multiple formats, resolutions and viewport sizes

• It can create more than 36 combinations!

Page 45: Responsive Images and Performance

<picture>…<source type=“image/webp" srcset=“image_lo.webp 1x, image_hi.webp 2x, image_uhi.webp 3x” media=“(min-width: 400px)”>…</picture>

Page 46: Responsive Images and Performance

Meet HTTP Client Hints

• It’s an extension to HTTP • The browser will expose data to the server • Reduce the need of client-side media queries

Page 47: Responsive Images and Performance

Hello HTTP Client Hints

<meta http-equiv="Accept-CH" content="DPR, Viewport-Width, Downlink">

Page 48: Responsive Images and Performance

Meet HTTP Client Hints

• Every image request will include headers: • DPR • Width • Viewport-Width • Downlink • Save-Data

Page 49: Responsive Images and Performance

Save Data please!

• Every image request will include headers: • Save-Data

Page 50: Responsive Images and Performance

What about Animated GIFs?

Page 51: Responsive Images and Performance

The Animated GIF nightmare

• GIF is a very old format • Extremely Inefficient • 8 bits only

Page 52: Responsive Images and Performance

Animation format: Animated PNG

• 8, 24 and 32 bits available • Transparent animations

APNG

• Polyfill available

Page 53: Responsive Images and Performance

Animation format: Animated WebP

• Lossy or lossless

Page 54: Responsive Images and Performance

Animation format: Muted Inline Videos

• Compression (MP4 H265, WebM V9) • Only with muted videos • On iOS 10, with webkit-playsinline

• Polyfill available10+53+

Page 55: Responsive Images and Performance

What’s next

Page 56: Responsive Images and Performance

New format: BPG

• iPhone 7+ • Desktop

224Kb 121Kb

Better Portable Graphics (lossy and lossless)

-70%lossy

Page 57: Responsive Images and Performance

New format: BPG

• iPhone 7+ • Desktop

224Kb 121Kb

Better Portable Graphics

-70%

• JavaScript decoder

lossy

Page 58: Responsive Images and Performance

New format: FLIF

• iPhone 7+ • Desktop

1.5Mb 0.8Mb

Free Lossless Image Format - Alpha!

-43%lossless

Page 59: Responsive Images and Performance

New format: FLIF

• iPhone 7+ • Desktop

1.5Mb 0.8Mb

Free Lossless Image Format - Alpha!

-43%lossless

Great for Responsive using Progressiveness

Page 60: Responsive Images and Performance

Use Service Workers

• You can convert files on the fly • There is a BPG SW-based decoder

future

Page 61: Responsive Images and Performance
Page 62: Responsive Images and Performance

final thoughts

- performance is key for success - don’t send pixels that won’t be rendered - find the balance: file size, memory, resolution - use new formats and client hints

Page 63: Responsive Images and Performance

Foto de freefoto.com

[email protected]@firt

firt.mobi/hpmw firt.mobi/mh5