Slide 1

Slide 1 text

1 Improving Performance with Responsive Images David Newton | St. Michael’s Hospital

Slide 2

Slide 2 text

2 2 https://github.com/nwtn/pres-respimg-perf-nagw

Slide 3

Slide 3 text

3 “Good performance is good design” —Brad Frost

Slide 4

Slide 4 text

Responsive Web Design 4

Slide 5

Slide 5 text

5

Slide 6

Slide 6 text

6

Slide 7

Slide 7 text

7

Slide 8

Slide 8 text

8

Slide 9

Slide 9 text

9

Slide 10

Slide 10 text

10 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 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

14

Slide 15

Slide 15 text

15

Slide 16

Slide 16 text

16

Slide 17

Slide 17 text

17 1. A flexible, grid-based layout, 2. Flexible images and media, 3. Media queries, a module from the CSS3 specification

Slide 18

Slide 18 text

18 1. A flexible, grid-based layout, 2. Flexible images and media, 3. Media queries, a module from the CSS3 specification

Slide 19

Slide 19 text

Responsive Images 19

Slide 20

Slide 20 text

20 img { max-width: 100%; }

Slide 21

Slide 21 text

21

Slide 22

Slide 22 text

22

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

24

Slide 25

Slide 25 text

25

Slide 26

Slide 26 text

26

Slide 27

Slide 27 text

Performance 27

Slide 28

Slide 28 text

28 Average web page size: 1,860 KB
 
 Images account for: 1,180 KB (>63%)
 
 HTTP Archive, September 1 2014

Slide 29

Slide 29 text

29

Slide 30

Slide 30 text

30 2x resolution = 4x as many pixels ! 3x resolution = 9x as many pixels ! 4x resolution = 16x as many pixels

Slide 31

Slide 31 text

31 energy more pixels = more money time

Slide 32

Slide 32 text

32 —Dave Rupert

Slide 33

Slide 33 text

33 “Good performance is good design” —Brad Frost

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

Responsive Images 36 (Again)

Slide 37

Slide 37 text

37

Slide 38

Slide 38 text

38

Slide 39

Slide 39 text

39

Slide 40

Slide 40 text

40 SVG WebP JPEG XR

Slide 41

Slide 41 text

41

Slide 42

Slide 42 text

42 + srcset + sizes
 
 http://whatwg.org/html#the-picture-element

Slide 43

Slide 43 text

43 Using CSS is a bad idea.

Slide 44

Slide 44 text

44 Using JavaScript is a bad idea.

Slide 45

Slide 45 text

45 + srcset + sizes
 
 http://whatwg.org/html#the-picture-element

Slide 46

Slide 46 text

46 Firefox (Gecko) srcset (partial) N/A srcset (full) + sizes behind a flag: FF33 on by default: FF34? picture behind a flag: FF33 on by default: FF34?

Slide 47

Slide 47 text

47 Firefox (Gecko) Chrome/Opera (Blink) srcset (partial) N/A Chrome 34 srcset (full) + sizes behind a flag: FF33 on by default: FF34? behind a flag: Chrome 37 on by default: Chrome 38 picture behind a flag: FF33 on by default: FF34? behind a flag: Chrome 37 on by default: Chrome 38

Slide 48

Slide 48 text

48 Firefox (Gecko) Chrome/Opera (Blink) Safari (WebKit) srcset (partial) N/A Chrome 34 Safari 8 srcset (full) + sizes behind a flag: FF33 on by default: FF34? behind a flag: Chrome 37 on by default: Chrome 38 Safari 8.1? picture behind a flag: FF33 on by default: FF34? behind a flag: Chrome 37 on by default: Chrome 38 Safari 8.1?

Slide 49

Slide 49 text

49 Firefox (Gecko) Chrome/Opera (Blink) Safari (WebKit) IE (Trident) srcset (partial) N/A Chrome 34 Safari 8 12? srcset (full) + sizes behind a flag: FF33 on by default: FF34? behind a flag: Chrome 37 on by default: Chrome 38 Safari 8.1? 12? picture behind a flag: FF33 on by default: FF34? behind a flag: Chrome 37 on by default: Chrome 38 Safari 8.1? 12?

Slide 50

Slide 50 text

50 Picturefill by Scott Jehl ! https://github.com/scottjehl/picturefill

Slide 51

Slide 51 text

Markup 51

Slide 52

Slide 52 text

Markup 52 Device Pixel Ratio-Switching

Slide 53

Slide 53 text

53 A rad wolf

Slide 54

Slide 54 text

54 A rad wolf

Slide 55

Slide 55 text

55 A rad wolf

Slide 56

Slide 56 text

56 A rad wolf

Slide 57

Slide 57 text

57 A rad wolf

Slide 58

Slide 58 text

58 A rad wolf

Slide 59

Slide 59 text

Markup 59 Viewport- and screen resolution-switching

Slide 60

Slide 60 text

60 A rad wolf

Slide 61

Slide 61 text

61 A rad wolf

Slide 62

Slide 62 text

62 A rad wolf

Slide 63

Slide 63 text

63 A rad wolf

Slide 64

Slide 64 text

64 A rad wolf

Slide 65

Slide 65 text

65 A rad wolf

Slide 66

Slide 66 text

66 A rad wolf

Slide 67

Slide 67 text

67 A rad wolf NO!

Slide 68

Slide 68 text

68 A rad wolf

Slide 69

Slide 69 text

69

Slide 70

Slide 70 text

70 A rad wolf

Slide 71

Slide 71 text

71 A rad wolf

Slide 72

Slide 72 text

72 A rad wolf

Slide 73

Slide 73 text

73 A rad wolf

Slide 74

Slide 74 text

Markup 74 File type-switching

Slide 75

Slide 75 text

75 A rad wolf

Slide 76

Slide 76 text

76 A rad wolf

Slide 77

Slide 77 text

77 A rad wolf

Slide 78

Slide 78 text

78 A rad wolf

Slide 79

Slide 79 text

79 A rad wolf

Slide 80

Slide 80 text

80 A rad wolf

Slide 81

Slide 81 text

81 A rad wolf

Slide 82

Slide 82 text

82 A rad wolf

Slide 83

Slide 83 text

Markup 83 Art direction

Slide 84

Slide 84 text

84 A rad wolf

Slide 85

Slide 85 text

85

Slide 86

Slide 86 text

86

Slide 87

Slide 87 text

87

Slide 88

Slide 88 text

88 A rad wolf

Slide 89

Slide 89 text

89 A rad wolf

Slide 90

Slide 90 text

90 A rad wolf

Slide 91

Slide 91 text

91 A rad wolf

Slide 92

Slide 92 text

92 A rad wolf

Slide 93

Slide 93 text

93 A rad wolf

Slide 94

Slide 94 text

94 A rad wolf

Slide 95

Slide 95 text

Markup 95 All the things!

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

97 A rad wolf

Slide 98

Slide 98 text

98 A rad wolf

Slide 99

Slide 99 text

99 http://whatwg.org/html#the-picture-element

Slide 100

Slide 100 text

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

Slide 101

Slide 101 text

1 Improving Performance with Responsive Images David Newton | St. Michael’s Hospital

Slide 102

Slide 102 text

1 Improving Performance with Responsive Images David Newton | St. Michael’s Hospital RESPONSIBLE!

Slide 103

Slide 103 text

1. Responsive images 2. 3. 4. 5. 6. 103

Slide 104

Slide 104 text

104 1. Responsive images 2. Image optimization 3. 4. 5. 6.

Slide 105

Slide 105 text

105 ImageOptim
 https://imageoptim.com/ ! ImageOptim-CLI http://jamiemason.github.io/ImageOptim-CLI/ ! Scour https://launchpad.net/scour ! grunt-svgmin https://github.com/sindresorhus/grunt-svgmin

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

107 1. Responsive images 2. Image optimization 3. 4. 5. 6.

Slide 108

Slide 108 text

108 1. Responsive images 2. Image optimization 3. Deferred image loading 4. 5. 6.

Slide 109

Slide 109 text

109

Slide 110

Slide 110 text

110

Slide 111

Slide 111 text

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

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

113 1. Responsive images 2. Image optimization 3. Deferred image loading 4. 5. 6.

Slide 114

Slide 114 text

114 1. Responsive images 2. Image optimization 3. Deferred image loading 4. Caching 5. 6.

Slide 115

Slide 115 text

115 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 116

Slide 116 text

116 1. Responsive images 2. Image optimization 3. Deferred image loading 4. Caching 5. 6.

Slide 117

Slide 117 text

117 1. Responsive images 2. Image optimization 3. Deferred image loading 4. Caching 5. CDNs 6.

Slide 118

Slide 118 text

118 1. Responsive images 2. Image optimization 3. Deferred image loading 4. Caching 5. CDNs 6. Fewer images

Slide 119

Slide 119 text

119

Slide 120

Slide 120 text

120 1. Responsive images 2. Image optimization 3. Deferred image loading 4. Caching 5. CDNs 6. Fewer images

Slide 121

Slide 121 text

Impact 121

Slide 122

Slide 122 text

122

Slide 123

Slide 123 text

123

Slide 124

Slide 124 text

124 HTML 2 KB Scripts 29 KB CSS 1 KB Images 661 KB Total: 693 KB

Slide 125

Slide 125 text

125 Unoptimized (Firefox) Unoptimized (Safari/iOS) Load time 2.2s 2.1s

Slide 126

Slide 126 text

▪ Responsive images #1: use srcset and sizes to serve images at an appropriate size
 ▪ Responsive images #2: use picture, source, and type to serve SVG and WebP versions where possible
 ▪ Optimization: progressive encoding; use ImageOptim and Scour to optimize file size; serve SVGs gzipped
 ▪ Deferred image loading: use a modified lazyload.js to defer loading of images that are below the fold 126

Slide 127

Slide 127 text

127 2 KB 29 KB 1 KB Images 661 KB Total: 693KB

Slide 128

Slide 128 text

128 HTML 3 KB Scripts 33 KB CSS 1 KB Images 253 KB Total: 290KB (~58% savings) 2 KB 29 KB 1 KB Images 661 KB Total: 693KB

Slide 129

Slide 129 text

129 HTML 3 KB Scripts 33 KB CSS 1 KB Images 87 KB Total: 119 KB (~83% savings) 2 KB 29 KB 1 KB Images 661 KB Total: 693 KB

Slide 130

Slide 130 text

130 Unoptimized (Firefox/Desktop) Optimized (Firefox/Desktop) Unoptimized (Safari/iOS) Optimized (Safari/iOS) Load time 2.2s 2.0s 2.1s 1.7s

Slide 131

Slide 131 text

131

Slide 132

Slide 132 text

132 “Good performance is good design” —Brad Frost

Slide 133

Slide 133 text

133 “Responsible images are good design” —Dave Newton

Slide 134

Slide 134 text

134 Dave Newton 
 Twitter: @newtron GitHub: @nwtn Email: [email protected]
 
 Slides, links, image credits, and more:
 https://github.com/nwtn/pres-respimg-perf-nagw