Slide 1

Slide 1 text

David Newton, St. Michael’s Hospital 1 1 Using Responsive Images Responsibly: Performance & Accessibility: WordCamp Toronto 2014 Twitter: @newtron Github: @nwtn Email: [email protected] Slides: https://github.com/nwtn/pres-respimg-perf-wcto

Slide 2

Slide 2 text

2 Why accessibility? Why performance?

Slide 3

Slide 3 text

3 What is “accessibility”?

Slide 4

Slide 4 text

“ 4 ‘Disability’ means… any degree of physical disability, infirmity, malformation or disfigurement that is caused by bodily injury, birth defect or illness… —Accessibility for Ontarians with Disabilities Act

Slide 5

Slide 5 text

5 Accessibility Deliver a great experience to all users, regardless of their ability.

Slide 6

Slide 6 text

“ 6 Following these guidelines will make content accessible to a wider range of people with disabilities, including blindness and low vision, deafness and hearing loss, learning disabilities, cognitive limitations, limited movement, speech disabilities, photosensitivity and combinations of these. Following these guidelines will also often make your Web content more usable to users in general. —Web Content Accessibility Guidelines 2.0 (emphasis mine)

Slide 7

Slide 7 text

7 Progressive enhancement

Slide 8

Slide 8 text

“ 8 The goal of Web design is not merely to dazzle, but to deliver information to the widest audience possible. …Compromise should not come at the expense of the user, but rather in terms of the native capabilities of the user’s choice of device.… Leave no one behind. —Steven Champeon, Inclusive Web Design for the Future (emphasis mine)

Slide 9

Slide 9 text

9 Progressive enhancement Deliver a great experience to all users, regardless of their browser’s ability.

Slide 10

Slide 10 text

10 Responsive web design

Slide 11

Slide 11 text

“ 11 Rather than creating disconnected designs, each tailored to a particular device or browser, we should instead treat them as facets of the same experience. —Ethan Marcotte, Responsive Web Design (emphasis mine)

Slide 12

Slide 12 text

12 Responsive web design Deliver a great experience to all users, regardless of their viewing context.

Slide 13

Slide 13 text

13 Web performance

Slide 14

Slide 14 text

“ 14 Many of us are fortunate to live in high bandwidth regions, but there are still large portions of the world that do not. By keeping your client side code small and lightweight, you can literally open your product up to new markets. —Chris Zacharias, Page Weight Matters (emphasis mine)

Slide 15

Slide 15 text

15 Web performance Deliver a great experience to all users, regardless of their connection.

Slide 16

Slide 16 text

16 Accessibility Progressive enhancement Responsive web design Web performance

Slide 17

Slide 17 text

17 Universal design Deliver a great experience to all users.

Slide 18

Slide 18 text

17 Universal design Deliver a great experience to all users.

Slide 19

Slide 19 text

18 Accessibility Progressive enhancement Responsive web design Web performance Universal web design Accessibility Progressive enhancement Responsive web design Web performance

Slide 20

Slide 20 text

18 Accessibility Progressive enhancement Responsive web design Web performance Universal web design Accessibility Progressive enhancement Responsive web design Web performance

Slide 21

Slide 21 text

18 Universal web design Accessibility Progressive enhancement Responsive web design Web performance

Slide 22

Slide 22 text

“ 19 Universal design is the design of products and environments to be usable by all people, to the greatest extent possible, without the need for adaptation or specialized design. —Ronald L. Mace

Slide 23

Slide 23 text

20 Why images?

Slide 24

Slide 24 text

21 63% of Americans used a phone to access the internet 34% of Americans used a mobile device as their primary way to access the web

Slide 25

Slide 25 text

“ 22 More human beings today have access to a cellphone than…a clean toilet. –Anand Giridharadas, New York Times April 10 2010

Slide 26

Slide 26 text

“ 22 More human beings today have access to a cellphone than…a clean toilet. –Anand Giridharadas, New York Times April 10 2010

Slide 27

Slide 27 text

23 — OpenSignal, Android Fragmentation Visualized (August 2014)

Slide 28

Slide 28 text

24 —https://twitter.com/lukew/status/507880029737328640/photo/1

Slide 29

Slide 29 text

25 img { max-width: 100%; }

Slide 30

Slide 30 text

26

Slide 31

Slide 31 text

27

Slide 32

Slide 32 text

28 A solution: Serve one big image and let the browser scale it

Slide 33

Slide 33 text

29

Slide 34

Slide 34 text

30

Slide 35

Slide 35 text

31 —HTTP Archive, November 1 2014 Stylesheets 57 KB HTML 60 KB Flash 76 KB Other 152 KB Scripts 305 KB Images 1,206 KB Total 1,925 KB

Slide 36

Slide 36 text

32

Slide 37

Slide 37 text

33

Slide 38

Slide 38 text

34 2x resolution = 4x as many pixels 3x resolution = 9x as many pixels 4x resolution = 16x as many pixels

Slide 39

Slide 39 text

35 more pixels = more energy more pixels = more money more pixels = more time

Slide 40

Slide 40 text

36 — Dave Rupert , Mo’ Pixels, Mo’ Problems Caption

Slide 41

Slide 41 text

37 Why images?

Slide 42

Slide 42 text

38 Responsive images

Slide 43

Slide 43 text

39 A solution: Serve one big image and let the browser scale it

Slide 44

Slide 44 text

40 A better solution: Serve an appropriate image to each user

Slide 45

Slide 45 text

41

Slide 46

Slide 46 text

42

Slide 47

Slide 47 text

43

Slide 48

Slide 48 text

44 SVG WebP JPEG XR JPEG 2000

Slide 49

Slide 49 text

45

Slide 50

Slide 50 text

46 Using JavaScript is a bad idea.

Slide 51

Slide 51 text

47 Using CSS is a bad idea.

Slide 52

Slide 52 text

48 http://whatwg.org/html#the-picture-element Responsive images specification

Slide 53

Slide 53 text

49 Firefox (Gecko) Chrome/Opera (Blink) Safari (WebKit) Internet Explorer (Trident) srcset (x) N/A Chrome 34 Opera 21 Works now! Safari 8 Works now! N/A? srcset (x & w) + sizes Behind a flag: FF 32 On by default: FF 36? Chrome 38 Opera 25 Works now! Safari 8.1? 12? picture Behind a flag: FF 33 On by default: FF 36? Chrome 38 Opera 25 Works now! Safari 8.1? 12?

Slide 54

Slide 54 text

50 https://github.com/scottjehl/picturefill Picturefill by Scott Jehl http://filamentgroup.com/lab/to-picturefill.html To Picturefill, or not to Picturefill

Slide 55

Slide 55 text

51 https://github.com/ResponsiveImagesCG/ wp-tevko-responsive-images WP-tevko-responsive-images

Slide 56

Slide 56 text

52 Resolution switching Markup

Slide 57

Slide 57 text

52 Resolution switching Markup

Slide 58

Slide 58 text

53 A rad wolf

Slide 59

Slide 59 text

54 A rad wolf

Slide 60

Slide 60 text

55 A rad wolf

Slide 61

Slide 61 text

56 A rad wolf

Slide 62

Slide 62 text

57 A rad wolf

Slide 63

Slide 63 text

58 A rad wolf

Slide 64

Slide 64 text

59 A rad wolf

Slide 65

Slide 65 text

60 Viewport (and resolution!) switching Markup

Slide 66

Slide 66 text

61 A rad wolf

Slide 67

Slide 67 text

62 A rad wolf

Slide 68

Slide 68 text

63 A rad wolf

Slide 69

Slide 69 text

64 A rad wolf

Slide 70

Slide 70 text

65 A rad wolf

Slide 71

Slide 71 text

66 A rad wolf

Slide 72

Slide 72 text

67 A rad wolf

Slide 73

Slide 73 text

68 A rad wolf

Slide 74

Slide 74 text

69 A rad wolf

Slide 75

Slide 75 text

70 A rad wolf

Slide 76

Slide 76 text

71 A rad wolf

Slide 77

Slide 77 text

72

Slide 78

Slide 78 text

73 A rad wolf

Slide 79

Slide 79 text

74 A rad wolf

Slide 80

Slide 80 text

75 File type switching Markup

Slide 81

Slide 81 text

76 A rad wolf

Slide 82

Slide 82 text

77 A rad wolf

Slide 83

Slide 83 text

78 A rad wolf

Slide 84

Slide 84 text

79 A rad wolf

Slide 85

Slide 85 text

80 A rad wolf

Slide 86

Slide 86 text

81 A rad wolf

Slide 87

Slide 87 text

82 A rad wolf

Slide 88

Slide 88 text

83 Art direction Markup

Slide 89

Slide 89 text

84 —Adventure Time

Slide 90

Slide 90 text

85

Slide 91

Slide 91 text

86

Slide 92

Slide 92 text

87 A rad wolf

Slide 93

Slide 93 text

88 A rad wolf

Slide 94

Slide 94 text

89 A rad wolf

Slide 95

Slide 95 text

90 A rad wolf

Slide 96

Slide 96 text

91 A rad wolf

Slide 97

Slide 97 text

92 A rad wolf

Slide 98

Slide 98 text

93 All the things! Markup a.k.a. the scary slide

Slide 99

Slide 99 text

93 All the things! Markup a.k.a. the scary slide

Slide 100

Slide 100 text

94 A rad wolf

Slide 101

Slide 101 text

95 A rad wolf

Slide 102

Slide 102 text

96 http://whatwg.org/html#the-picture-element Responsive images specification

Slide 103

Slide 103 text

97 Responsible images

Slide 104

Slide 104 text

98 1. Responsive images

Slide 105

Slide 105 text

99 1. Responsive images 2. Image optimization

Slide 106

Slide 106 text

100 https://imageoptim.com/ ImageOptim http://jamiemason.github.io/ImageOptim-CLI/ ImageOptim-CLI https://github.com/svg/svgo-gui SVGO-GUI https://github.com/svg/svgo SVGO

Slide 107

Slide 107 text

101 SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE "image/svg+xml" Note: Apache is confusing and I’m not guaranteeing this will work.

Slide 108

Slide 108 text

102 1. Responsive images 2. Image optimization 3. Deferred image loading

Slide 109

Slide 109 text

103

Slide 110

Slide 110 text

104

Slide 111

Slide 111 text

105 http://www.w3.org/TR/resource-priorities/ Resource Priorities https://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2014-August/297533.html Preloading and deferred loading of scripts and other resources

Slide 112

Slide 112 text

106 http://css-tricks.com/snippets/javascript/lazy-loading-images/ LazyLoad JS scripts and plugins, e.g.:

Slide 113

Slide 113 text

107 1. Responsive images 2. Image optimization 3. Deferred image loading 4. Caching & CDNs

Slide 114

Slide 114 text

108 ExpiresActive on ExpiresDefault "access plus 1 month" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" Note: Apache is confusing and I’m not guaranteeing this will work.

Slide 115

Slide 115 text

109 1. Responsive images 2. Image optimization 3. Deferred image loading 4. Caching & CDNs 5. Appropriate contrast and colour

Slide 116

Slide 116 text

110 7% 8% 10% 11% 29% 35% April May June July August September

Slide 117

Slide 117 text

111 7% 8% 10% 11% 29% 35% April May June July August September

Slide 118

Slide 118 text

112

Slide 119

Slide 119 text

113 http://colororacle.org/ Color Oracle

Slide 120

Slide 120 text

114 September 7% August 8% July 10% June 11% May 29% April 35%

Slide 121

Slide 121 text

115 1. Responsive images 2. Image optimization 3. Deferred image loading 4. Caching & CDNs 5. Appropriate contrast and colour 6. Text-based alternatives

Slide 122

Slide 122 text

116 [alt] [aria-describedby], [aria-labelledby] [longdesc] SVG elements and attributes

Slide 123

Slide 123 text

117 http://www.w3.org/TR/html-alt-techniques/ HTML5: Techniques for providing useful text alternatives http://www.w3.org/WAI/GL/wiki/Using_aria-describedby_to_provide_descriptions_of_images Using aria-describedby to provide descriptions of images http://w3c.github.io/test-results/html-longdesc/cr-report.html longdesc Implementation Report http://www.paciellogroup.com/blog/2013/12/using-aria-enhance-svg-accessibility/ Using ARIA to enhance SVG accessibility http://www.w3.org/WAI/GL/wiki/Using_aria-labelledby_to_provide_a_text_alternative_for_non- text_content Using aria-labelledby to provide a text alternative for non-text content

Slide 124

Slide 124 text

118 1. Responsive images 2. Image optimization 3. Deferred image loading 4. Caching & CDNs 5. Appropriate contrast and colour 6. Text-based alternatives 7. Fewer images!

Slide 125

Slide 125 text

119 Performance impact

Slide 126

Slide 126 text

120

Slide 127

Slide 127 text

121

Slide 128

Slide 128 text

122 Unoptimized Optimized + Responsive Optimized + Responsive + Lazyload CSS 1 KB 1 KB 1 KB HTML 2 KB 3 KB 3 KB Scripts 29 KB 33 KB 33 KB Images 661 KB 253 KB 87 KB Total 693 KB 290 KB (~58% savings) 119 KB (~83% savings)

Slide 129

Slide 129 text

123 Browser Unoptimized Optimized + Responsive + Lazyload Firefox (Desktop) 2.2 s 2.0 s Safari (iOS) 2.1 s 1.7 s Average 2.2 s 1.9 s (~14% savings)

Slide 130

Slide 130 text

124

Slide 131

Slide 131 text

125 Accessibility Progressive enhancement Responsive web design Web performance

Slide 132

Slide 132 text

David Newton, St. Michael’s Hospital 126 Using Responsive Images Responsibly: Performance & Accessibility: WordCamp Toronto 2014 Twitter: @newtron Github: @nwtn Email: [email protected] Slides: https://github.com/nwtn/pres-respimg-perf-wcto