Slide 1

Slide 1 text

1 Improving performance with responsive (and responsible!) images

Slide 2

Slide 2 text

1 Improving performance with responsive (and responsible!) images Don’t tell anybody, but this is an HTML talk.

Slide 3

Slide 3 text

2

Slide 4

Slide 4 text

2

Slide 5

Slide 5 text

2

Slide 6

Slide 6 text

3 twitter @newtron github @nwtn slides nwtn.ca/d

Slide 7

Slide 7 text

4 Web performance

Slide 8

Slide 8 text

“ 5 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 9

Slide 9 text

“ 6 Good performance is good design. —Brad Frost

Slide 10

Slide 10 text

7 Why images?

Slide 11

Slide 11 text

8 —Marc Andreessen, www-talk, February 1993

Slide 12

Slide 12 text

9 Fonts 114 KB CSS 74 KB Video 187 KB HTML 52 KB Scripts 368 KB Other 4 KB Images 1,412 KB Total: 2,219 KB

Slide 13

Slide 13 text

10

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

12

Slide 16

Slide 16 text

13 — OpenSignal, Android Fragmentation Visualized (August 2014)

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

15 A problem: We want images to look good e’rywhere

Slide 19

Slide 19 text

16 img { max-width: 100%; }

Slide 20

Slide 20 text

17

Slide 21

Slide 21 text

18

Slide 22

Slide 22 text

19

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

21

Slide 25

Slide 25 text

22

Slide 26

Slide 26 text

23 Bullet 1 Bullet 2 Bullet 3

Slide 27

Slide 27 text

24 Bullet 1 Bullet 2 Bullet 3

Slide 28

Slide 28 text

25

Slide 29

Slide 29 text

26 more pixels = more energy more pixels = more memory more pixels = more time

Slide 30

Slide 30 text

27 A problem: We want images to look good e’rywhere

Slide 31

Slide 31 text

28 A harder problem: We want images to look good e’rywhere, without hurting the user experience

Slide 32

Slide 32 text

29 Responsive images

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

32

Slide 36

Slide 36 text

33

Slide 37

Slide 37 text

34

Slide 38

Slide 38 text

35 SVG WebP JPEG XR JPEG 2000

Slide 39

Slide 39 text

36

Slide 40

Slide 40 text

37 Using CSS is a bad idea.

Slide 41

Slide 41 text

38 Using JavaScript is a bad idea.

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

40 Markup

Slide 44

Slide 44 text

40 Resolution switching Markup

Slide 45

Slide 45 text

41 A rad wolf

Slide 46

Slide 46 text

42 A rad wolf

Slide 47

Slide 47 text

43 A rad wolf

Slide 48

Slide 48 text

44 A rad wolf

Slide 49

Slide 49 text

45 A rad wolf

Slide 50

Slide 50 text

46 A rad wolf

Slide 51

Slide 51 text

47 A rad wolf

Slide 52

Slide 52 text

48 Viewport (and resolution!) switching Markup

Slide 53

Slide 53 text

49 A rad wolf

Slide 54

Slide 54 text

50 A rad wolf

Slide 55

Slide 55 text

51 A rad wolf

Slide 56

Slide 56 text

52 A rad wolf

Slide 57

Slide 57 text

53 A rad wolf

Slide 58

Slide 58 text

54 A rad wolf

Slide 59

Slide 59 text

55 A rad wolf

Slide 60

Slide 60 text

56 A rad wolf

Slide 61

Slide 61 text

57 A rad wolf

Slide 62

Slide 62 text

58

Slide 63

Slide 63 text

59 A rad wolf

Slide 64

Slide 64 text

60 A rad wolf

Slide 65

Slide 65 text

61 File type switching Markup

Slide 66

Slide 66 text

62 A rad wolf

Slide 67

Slide 67 text

63 A rad wolf

Slide 68

Slide 68 text

64 A rad wolf

Slide 69

Slide 69 text

65 A rad wolf

Slide 70

Slide 70 text

66 A rad wolf

Slide 71

Slide 71 text

67 A rad wolf

Slide 72

Slide 72 text

68 A rad wolf

Slide 73

Slide 73 text

69 Art direction Markup

Slide 74

Slide 74 text

70 —Adventure Time

Slide 75

Slide 75 text

71

Slide 76

Slide 76 text

72

Slide 77

Slide 77 text

73 A rad wolf

Slide 78

Slide 78 text

74 A rad wolf

Slide 79

Slide 79 text

75 A rad wolf

Slide 80

Slide 80 text

76 A rad wolf

Slide 81

Slide 81 text

77 A rad wolf

Slide 82

Slide 82 text

78 A rad wolf

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

80 A rad wolf

Slide 86

Slide 86 text

A rad wolf 81

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

83 http://codepen.io/Tigt/blog/when-responsive-images-get-ugly When responsive images get ugly

Slide 89

Slide 89 text

84 You can use this now!

Slide 90

Slide 90 text

85 Firefox (Gecko) Chrome/Opera (Blink) Safari (WebKit) Edge srcset + sizes Works now! Firefox 38 Works now! Chrome 34 Opera 21 Works now! Safari 9 iOS 9 Works now! Edge 13 picture Works now! Firefox 38 Works now! Chrome 38 Opera 25 Almost there… Works now! Edge 13

Slide 91

Slide 91 text

86 http://picturefill.responsiveimages.org/ Picturefill by Scott Jehl & others http://filamentgroup.com/lab/to-picturefill.html To Picturefill, or not to Picturefill

Slide 92

Slide 92 text

87 Responsive images are a pain in the butt

Slide 93

Slide 93 text

88

Slide 94

Slide 94 text

89 https://www.npmjs.com/package/grunt-respimg grunt-respimg

Slide 95

Slide 95 text

90 https://github.com/nwtn/php-respimg/ php-respimg

Slide 96

Slide 96 text

https://www.npmjs.com/package/grunt-responsive-images-extender/ 91 grunt-responsive-images-extender

Slide 97

Slide 97 text

http://www.smashingmagazine.com/2015/06/efficient- image-resizing-with-imagemagick/ Efficient image resizing With ImageMagick 92

Slide 98

Slide 98 text

93 Responsible images

Slide 99

Slide 99 text

94 1. Responsive images

Slide 100

Slide 100 text

95 1. Responsive images 2. Image optimization

Slide 101

Slide 101 text

96 https://imageoptim.com/ ImageOptim https://github.com/toy/image_optim image_optim https://github.com/svg/svgo-gui SVGO-GUI https://github.com/svg/svgo SVGO

Slide 102

Slide 102 text

97 SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE "image/svg+xml"

Slide 103

Slide 103 text

98 1. Responsive images 2. Image optimization 3. Deferred image loading (a.k.a. “lazy loading”)

Slide 104

Slide 104 text

No content

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

101 http://afarkas.github.io/lazysizes/ LazyLoad JS scripts and plugins, e.g.:

Slide 107

Slide 107 text

102 1. Responsive images 2. Image optimization 3. Deferred image loading (a.k.a. “lazy loading”) 4. CDNs & Caching

Slide 108

Slide 108 text

103 1. Responsive images 2. Image optimization 3. Deferred image loading (a.k.a. “lazy loading”) 4. CDNs & Caching 5. Appropriate contrast and colour

Slide 109

Slide 109 text

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

Slide 110

Slide 110 text

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

Slide 111

Slide 111 text

106

Slide 112

Slide 112 text

107 http://colororacle.org/ Color Oracle

Slide 113

Slide 113 text

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

Slide 114

Slide 114 text

109 1. Responsive images 2. Image optimization 3. Deferred image loading (a.k.a. “lazy loading”) 4. CDNs & Caching 5. Appropriate contrast and colour 6. Text-based alternatives

Slide 115

Slide 115 text

110 [alt] [aria-describedby] [aria-labelledby] [longdesc] SVG

Slide 116

Slide 116 text

111 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 117

Slide 117 text

112 1. Responsive images 2. Image optimization 3. Deferred image loading (a.k.a. “lazy loading”) 4. CDNs & Caching 5. Appropriate contrast and colour 6. Text-based alternatives 7. Fewer images!

Slide 118

Slide 118 text

“ 113 Good performance is good design. —Brad Frost

Slide 119

Slide 119 text

114 https://www.shopify.com/careers We’re hiring!

Slide 120

Slide 120 text

115 twitter @newtron github @nwtn slides nwtn.ca/d