Adaptive Images in Responsive Design

A presentation at Funka Accessibility Days 2015 in April 2015 in Stockholm, Sweden by Christopher Schmitt

Slide 1

Slide 1

FUNKA 201 5 ADAPTIVE IM A G ES  IN RESPONSIVE WEB DESIGN CHRISTOPHER SCHMITT

@teleject

Slide 2

Slide 2

CHRISTOPHER SCHMITT @teleject

Slide 3

Slide 3

@teleject

Slide 4

Slide 4

@teleject Responsive Media Course http://goo.gl/fKgZ6I

Slide 5

Slide 5

@teleject http://CSSDevConf.com/

Slide 6

Slide 6

Slide 7

Slide 7

Slide 8

Slide 8

Slide 9

Slide 9

Slide 10

Slide 10

Slide 11

Slide 11

y x

Slide 12

Slide 12

Slide 13

Slide 13

Slide 14

Slide 14

Slide 15

Slide 15

http://cssspecificity.com

Slide 16

Slide 16

http://cssspecificity.com

Slide 17

Slide 17

http://cssspecificity.com

Slide 18

Slide 18

WHY DON’T WE ASK

THE BROWSER?

(cc) flic.kr /p/vUBHv

Slide 19

Slide 19

alert("User-agent header sent: " + navigator.userAgent );

Slide 20

Slide 20

alert("User-agent header sent: " + navigator.userAgent );

Slide 21

Slide 21

Mozilla/1.0 (Win3.1) http://www.useragentstring.com/

(cc) flic.kr /p/vUBHv

Slide 22

Slide 22

Mozilla/1.22 (compatible; MSIE 2.0; Windows 95) http://www.useragentstring.com/

Mozilla/1.0 (Win3.1)

(cc) flic.kr /p/vUBHv

Slide 23

Slide 23

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/ 534.55.3 (KHTML, like Gecko) Version/5.1.5 Safari/534.55.3 http://www.useragentstring.com/

(cc) flic.kr /p/vUBHv

Slide 24

Slide 24

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/ 534.55.3 (KHTML, like Gecko) Version/5.1.5 Safari/534.55.3 http://webaim.org/blog/user-agent-string-history/

(cc) flic.kr /p/vUBHv

Slide 25

Slide 25

FEATURE TESTING vs. BROWSER SNIFFING 1 2 3

Slide 26

Slide 26

FEATURE TESTING vs. BROWSER SNIFFING 1 Browser width 2 3

Slide 27

Slide 27

A scripting approach var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth ; myHeight = window.innerHeight ; } else if( document.documentElement &&
( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth ; myHeight = document.documentElement.clientHeight ; }
http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

Slide 28

Slide 28

The jQuery approach // returns width of browser viewport $( window ).width();
// returns height of browser viewport $( window ).height();
// returns width of HTML document $( document ).width();
// returns height of HTML document $(d ocument ).height(); http://api.jquery.com/width/ & http://api.jquery.com/height/

Slide 29

Slide 29

CSS media queries // default, mobile-1st CSS rules devices go here @media screen and ( min-width : 480 px) { ... }
@media screen and ( min-width : 600 px) { ... }
@media screen and ( min-width : 768 px) { ... }
@media screen and ( min-width : 910 px) { ... }

Slide 30

Slide 30

(cc) flic.kr /p/8Lo5Gk

Slide 31

Slide 31

BROWSER WIDTH GIVES US FRAME ,
NOT THE CANVAS

Slide 32

Slide 32

FEATURE TESTING vs. BROWSER SNIFFING 1 Browser width 2 Screen resolution 3

Slide 33

Slide 33

72

PPI HAS

(cc) flic.kr /p/6tjjRP

Slide 34

Slide 34

72 points -per-inch

72 pixels -per-inch

Slide 35

Slide 35

96

PPI IF A

Slide 36

Slide 36

72 points -per-inch
x [1+(1/3)]

= 96 PPI

Slide 37

Slide 37

78 μ m 78 μ m “RETINA” DISPLAYS 300ppi at 12 inches from the eyes

goo.gl /zpkFy

Slide 38

Slide 38

Slide 39

Slide 39

[In 2013, Intel sees their product line] offer a higher

resolution experience than a top-of-the-line 1080p HDTV.” http://liliputing.com/2012/04/intel-retina-laptop- desktop-displays-coming-in-2013.html

Slide 40

Slide 40

Slide 41

Slide 41

72 PPI

Slide 42

Slide 42

240

Slide 43

Slide 43

240 PPI

Slide 44

Slide 44

240 PPI

Slide 45

Slide 45

72 PPI

Slide 46

Slide 46

Slide 47

Slide 47

RETINA DISPLAYS = LARGER IMAGES, LARGER FILE SIZES

Slide 48

Slide 48

FEATURE TESTING vs. BROWSER SNIFFING 1 Browser width 2 Screen resolution 3 Bandwidth

Slide 49

Slide 49

SPEED TESTS HINDER SPEED, U SER E X PERIENCE

(cc) flic.kr /p/4DziUN

Slide 50

Slide 50

Testing for speed of an internet connection is like stepping in front of a car to see how fast it is.”

“ (cc) flic.kr /p/4DziUN

Slide 51

Slide 51

Testing for speed of an internet connection is like stepping in front of a car to see how fast it is.” But, Christopher, you only have to test it once .”

“ (cc) flic.kr /p/4DziUN

Slide 52

Slide 52

Speed test image https://github.com/adamdbradley/foresight.js

Slide 53

Slide 53

Speed test image https://github.com/adamdbradley/foresight.js

+50k

Slide 54

Slide 54

Native speed test // @Modernizr's network-connection.js connection = navigator.connection || {
type: 0 }, // polyfill isSlowConnection = connection.type == 3 || connection.type == 4

| /^[23]g$/.test(connection.type); http://davidbcalhoun.com/2010/using-navigator-connection-android

Slide 55

Slide 55

FEATURE TESTING vs. BROWSER SNIFFING 1 Browser width 2 Screen resolution 3 Bandwidth

Slide 56

Slide 56

1 HiSRC and others 2 3 GIMME THAT OLD SCHOOL IMG

Slide 57

Slide 57

SERIES OF CHECKS TO FIND OUT RESPONSIVE PATH FOR IMAGES...

Slide 58

Slide 58

DO NATIVE SPEED TEST FOR MOBILE DEVICES FIRST... http://davidbcalhoun.com/2010/using-navigator-connection-android

Slide 59

Slide 59

$.hisrc.devicePixelRatio = 1; if(window.devicePixelRatio !== undefined) {
$.hisrc.devicePixelRatio = window.devicePixelRatio

}; Check pixel density... https://gist.github.com/2428356

Slide 60

Slide 60

https://github.com/adamdbradley/foresight.js Force speed test

+50k

Slide 61

Slide 61

LESS THAN 4G MEANS MOBILE IMAGES LEFT IN PLACE

Slide 62

Slide 62

BETWEEN 4G & 
 300 Kbps MEANS REGULAR DESKTOP IMAGES SWAPPED IN

Slide 63

Slide 63

FAST SPEED & HIGH DENSITY, RETINA IMAGES SWAPPED IN https://github.com/crdeutsch/hisrc/tree/v2

Slide 64

Slide 64

BRINGING PROBLEMS BRINGING THE PAIN 1 2 3

Slide 65

Slide 65

BRINGING PROBLEMS 1 Double Taxation 2 3 BRINGING THE PAIN

Slide 66

Slide 66

http://css-tricks.com/which- responsive-images-solution- should-you-use/

Slide 67

Slide 67

24+ http://css-tricks.com/which- responsive-images-solution- should-you-use/

Slide 68

Slide 68

http://css-tricks.com/which- responsive-images-solution- should-you-use/

ALL SOLUTIONS HAVE 2x +

Slide 69

Slide 69

http://css-tricks.com/which- responsive-images-solution- should-you-use/

2x = MORE TIME COSTS

Slide 70

Slide 70

https://github.com/crdeutsch/hisrc/tree/v2 BRINGING THE PAIN 1 Double Taxation 2 Browser Preloader 3 BRINGING THE PAIN

Slide 71

Slide 71

http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.4 “A single-user client SHOULD NOT maintain more than 2 connections with any server or proxy. ”

Slide 72

Slide 72

https://developer.yahoo.com/blogs/ydn/high-performance-sites- rule-6-move-scripts-bottom-7200.html

Slide 73

Slide 73

https://developer.yahoo.com/blogs/ydn/high-performance-sites- rule-6-move-scripts-bottom-7200.html

Slide 74

Slide 74

http://www.stevesouders.com/blog/2013/04/26/i/ MODERN BROWSERS NOW USE PRELOADER

Slide 75

Slide 75

http://www.stevesouders.com/blog/2013/04/26/i/ PRELOADS IMAGES BEFORE PAGE FULLY DOWNLOADS

Slide 76

Slide 76

Slide 77

Slide 77

BRINGING PROBLEMS 1 Double Taxation 2 One Image, Still Not Ready 3 Browser Preloader BRINGING THE PAIN

Slide 78

Slide 78

#rwdimg

Slide 79

Slide 79

Slide 80

Slide 80

#rwdimg

Slide 81

Slide 81

#rwdimg

Slide 82

Slide 82

#rwdimg

Slide 83

Slide 83

#rwdimg

<link rel="shortcut icon" href="/assets/ favicon.ico " /> Favicon

Slide 84

Slide 84

#rwdimg

<link rel="apple-touch-icon-precomposed" sizes="144x144" href=" apple-touch-icon-144x144 -precomposed.png" /> <link rel="apple-touch-icon-precomposed" sizes="114x114" href=" apple-touch-icon-114x114 -precomposed.png" /> <link rel="apple-touch-icon-precomposed" sizes="72x72" href=" apple-touch-icon-72x72 -precomposed.png" /> <link rel="apple-touch-icon-precomposed" href=" apple-touch-icon -precomposed.png" /> Mobile iOS Bookmarks

Slide 85

Slide 85

#rwdimg

Slide 86

Slide 86

https://github.com/igrigorik/http-client-hints

Slide 87

Slide 87

1 2 3 RWD IMAG ES MEET THE NEW IMAGE ELEMENTS

Slide 88

Slide 88

1 2 3 RWD IMAG ES MEET THE NEW IMAGE ELEMENTS srcset

Slide 89

Slide 89

Basic Image Swap <img

src="swing-400.jpg" alt="Kettlebell Swing"> https://dev.opera.com/articles/native-responsive-images/

Slide 90

Slide 90

Image Fuel <img

srcset="swing-200.jpg 200w,

swing-400.jpg 400w,

swing-800.jpg 800w,

swing-1600.jpg 1600w"

src="swing-400.jpg" alt="Kettlebell Swing"> https://dev.opera.com/articles/native-responsive-images/

Slide 91

Slide 91

Image Fuel <img

srcset=" swing-200.jpg 200w,

swing-400.jpg 400w,

swing-800.jpg 800w,

swing-1600.jpg 1600w"

src="swing-400.jpg" alt="Kettlebell Swing"> https://dev.opera.com/articles/native-responsive-images/

Slide 92

Slide 92

Image Fuel <img

srcset="swing-200.jpg 200w ,

swing-400.jpg 400w ,

swing-800.jpg 800w ,

swing-1600.jpg 1600w "

src="swing-400.jpg" alt="Kettlebell Swing"> https://dev.opera.com/articles/native-responsive-images/

Slide 93

Slide 93

Image Fuel <img

srcset="swing-200.jpg 200w,

swing-400.jpg 400w,

swing-800.jpg 800w,

swing-1600.jpg 1600w"

src="swing-400.jpg" alt="Kettlebell Swing"> https://dev.opera.com/articles/native-responsive-images/

Slide 94

Slide 94

1 2 3 RWD IMAG ES MEET THE NEW IMAGE ELEMENTS srcset attribute sizes attribute

Slide 95

Slide 95

Basic Image Swap <img sizes="(min -width: 30em) 100vw,

(min-width: 50em) 50vw, 200px"

srcset="swing-200.jpg 200w,

swing-400.jpg 400w,

swing-800.jpg 800w,

swing-1600.jpg 1600w"

src="swing-400.jpg" alt="Kettlebell Swing"> https://dev.opera.com/articles/native-responsive-images/

Slide 96

Slide 96

Basic Image Swap <img sizes=" (min-width: 30em) 100vw ,

(min-width: 50em) 50vw, 200px"

srcset="swing-200.jpg 200w,

swing-400.jpg 400w,

swing-800.jpg 800w,

swing-1600.jpg 1600w"

src="swing-400.jpg" alt="Kettlebell Swing"> https://dev.opera.com/articles/native-responsive-images/

Slide 97

Slide 97

Basic Image Swap <img sizes="(min-width: 30em) 100vw,

(min-width: 50em) 50vw , 200px"

srcset="swing-200.jpg 200w,

swing-400.jpg 400w,

swing-800.jpg 800w,

swing-1600.jpg 1600w"

src="swing-400.jpg" alt="Kettlebell Swing"> https://dev.opera.com/articles/native-responsive-images/

Slide 98

Slide 98

Basic Image Swap <img sizes="(min-width: 30em) 100vw,

(min-width: 50em) 50vw , 200px "

srcset="swing-200.jpg 200w,

swing-400.jpg 400w,

swing-800.jpg 800w,

swing-1600.jpg 1600w"

src="swing-400.jpg" alt="Kettlebell Swing"> https://dev.opera.com/articles/native-responsive-images/

Slide 99

Slide 99

IT’S STILL UP TO BROWSER TO PICK WHICH IMAGE TO USE

Slide 100

Slide 100

Slide 101

Slide 101

1 2 3 <picture> srcset attribute sizes attribute RWD IMAG ES MEET THE NEW IMAGE ELEMENTS

Slide 102

Slide 102

Slide 103

Slide 103

Slide 104

Slide 104

<picture> <img src="small.jpg" alt=“That awesome Saints’ touchdown .">

Slide 105

Slide 105

<picture> <picture> <source media="(min-width: 45em)" srcset="large.jpg"> <source media="(min-width: 32em)" srcset="cropped .jpg"> <img src="small.jpg" alt=“That awesome Saints’ touchdown ."> </picture>

Slide 106

Slide 106

<picture> <picture> <source media="(min-width: 45em)" srcset="large.jpg"> <source media="(min-width: 32em)" srcset="cropped .jpg"> <img src="small.jpg" alt=“That awesome Saints’ touchdown ."> </picture>

Slide 107

Slide 107

<picture> <picture> <source media="(min-width: 45em)" srcset="large.jpg"> <source media="(min-width: 32em)"

srcset="cropped.jpg">

<img src="small.jpg" alt=“That awesome Saints’ 

touchdown ."> </picture>

Slide 108

Slide 108

<picture> <picture> <source media="(min-width: 45em)" srcset="large.jpg"> <source media="(min-width: 32em)" srcset="cropped .jpg"> <img src="small.jpg" alt=“That awesome Saints’ touchdown ."> </picture>

Slide 109

Slide 109

<picture> <picture> <source media="(min-width: 45em)" srcset="large.jpg"> <source media="(min-width: 32em)" srcset="cropped .jpg"> <img src="small.jpg" alt=“That awesome Saints’ touchdown ."> </picture>

Slide 110

Slide 110

USE <PICTURE>

POWER TO SOLVE ART DIRECTION

Slide 111

Slide 111

OTHERWISE,
KEEP USING
SRCSET & SIZES

Slide 112

Slide 112

Slide 113

Slide 113

http://responsivedesign.is/resources/images/picture-fill

Slide 114

Slide 114

https://wordpress.org/plugins/ricg-responsive-images/

Slide 115

Slide 115

1 2 3 <picture> srcset attribute sizes attribute RWD IMAG ES MEET THE NEW IMAGE ELEMENTS

Slide 116

Slide 116

Slide 117

Slide 117

y x

Slide 118

Slide 118

THANK YOU !  Newsletter - http://eepurl.com/TQAer

CHRISTOPHER SCHMITT