Slide 1

Slide 1 text

@deanohume Getting the LEAST from your images @rposbo

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Images are awesome

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

But they aren’t great for web performance

Slide 6

Slide 6 text

in fact....

Slide 7

Slide 7 text

They are greedy Stylesheets, HTML, etc Images JavaScript

Slide 8

Slide 8 text

Images are the biggest part of a web page Stylesheets, HTML, etc Images 60% JavaScript

Slide 9

Slide 9 text

56

Slide 10

Slide 10 text

The average web page makes 56 image requests per page * Source: HttpArchive.org

Slide 11

Slide 11 text

42% of all websites make over 50 image requests per page * Source: HttpArchive.org

Slide 12

Slide 12 text

The Web wouldn’t be the same without images

Slide 13

Slide 13 text

...So

Slide 14

Slide 14 text

We need to Make more efficient use of requests

Slide 15

Slide 15 text

We need to Make more efficient use of requests & Reduce the size of the images

Slide 16

Slide 16 text

We will look at

Slide 17

Slide 17 text

We will look at - Well known methods for reducing the size of your images and http requests

Slide 18

Slide 18 text

We will look at - Well known methods for reducing the size of your images and http requests - Some lesser known methods

Slide 19

Slide 19 text

We will look at - Well known methods for reducing the size of your images and http requests - Some lesser known methods - The future of images on the web

Slide 20

Slide 20 text

The Basics

Slide 21

Slide 21 text

Things everyone should be doing

Slide 22

Slide 22 text

Things everyone should be doing

Slide 23

Slide 23 text

Things everyone should be doing Image optimization

Slide 24

Slide 24 text

Things everyone should be doing Image optimization Spriting images

Slide 25

Slide 25 text

Things everyone should be doing Image optimization Spriting images Lazy loading

Slide 26

Slide 26 text

Image Optimization tools

Slide 27

Slide 27 text

Offline tools

Slide 28

Slide 28 text

- Image Magick - Jpeg Optim - Jpeg Tran Jpeg

Slide 29

Slide 29 text

- Image Magick - Jpeg Optim - Jpeg Tran Jpeg - Image Magick - Png Crush - Png Out Png

Slide 30

Slide 30 text

- Image Magick - Jpeg Optim - Jpeg Tran Jpeg - Image Magick - Png Crush - Png Out Png - Image Magick - Gifsicle Gif

Slide 31

Slide 31 text

Online tools

Slide 32

Slide 32 text

Online tools smushit.com kraken.io

Slide 33

Slide 33 text

Automate it!

Slide 34

Slide 34 text

kraken.io Optimisation APIs

Slide 35

Slide 35 text

kraken.io punypng.com/api Optimisation APIs

Slide 36

Slide 36 text

kraken.io punypng.com/api webresizer.com Optimisation APIs

Slide 37

Slide 37 text

The Baseline

Slide 38

Slide 38 text

Sprites

Slide 39

Slide 39 text

Take lots of little images

Slide 40

Slide 40 text

..and combine into one image

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

.norwegian_flag { width: 120px; height: 75px; background:url('/images/sprites/flag-sprite.png'); background-position: -240px -84px; }

Slide 44

Slide 44 text

1 request

Slide 45

Slide 45 text

1 request many images

Slide 46

Slide 46 text

Recommendations - No whitespace

Slide 47

Slide 47 text

Recommendations - No whitespace - Optimize & cache

Slide 48

Slide 48 text

Recommendations - No whitespace - Optimize & cache - Aim for similar palettes

Slide 49

Slide 49 text

Lazy Loading

Slide 50

Slide 50 text

Lazy Loading - Only load what the user sees

Slide 51

Slide 51 text

Lazy Loading - Only load what the user sees - Load images as the viewport moves

Slide 52

Slide 52 text

Lazy Loading - Only load what the user sees - Load images as the viewport moves - Reduce unnecessary HTTP requests

Slide 53

Slide 53 text

Loads every image

Slide 54

Slide 54 text

12x Requests

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

3x Requests

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

Benefits Reduced HTTP requests

Slide 61

Slide 61 text

Benefits Reduced HTTP requests A lot of users don’t scroll entire page

Slide 62

Slide 62 text

Benefits Reduced HTTP requests A lot of users don’t scroll entire page Faster initial page load times

Slide 63

Slide 63 text

Moving on..

Slide 64

Slide 64 text

WebP Images

Slide 65

Slide 65 text

WebP is a new image format

Slide 66

Slide 66 text

WebP is a new image format newish

Slide 67

Slide 67 text

They’re great because: 26% smaller than PNGs

Slide 68

Slide 68 text

They’re great because: 26% smaller than PNGs 25-35% smaller than JPGs

Slide 69

Slide 69 text

They’re great because: 26% smaller than PNGs 25-35% smaller than JPGs Image quality isn’t affected

Slide 70

Slide 70 text

Which means smaller web pages!

Slide 71

Slide 71 text

Jpg WebP

Slide 72

Slide 72 text

48.9 KB ?

Slide 73

Slide 73 text

48.9 KB 12.6 KB

Slide 74

Slide 74 text

75%

Slide 75

Slide 75 text

280 Kb ?

Slide 76

Slide 76 text

280 Kb 50 Kb

Slide 77

Slide 77 text

83%

Slide 78

Slide 78 text

WebP has it’s downsides

Slide 79

Slide 79 text

WebP has it’s downsides No IE support

Slide 80

Slide 80 text

WebP has it’s downsides No IE support No FireFox support

Slide 81

Slide 81 text

WebP has it’s downsides No IE support No FireFox support No iOS support

Slide 82

Slide 82 text

Support is growing!

Slide 83

Slide 83 text

How can I use it?

Slide 84

Slide 84 text

Use it today https://developers.google.com/speed/webp/ WebP converter tool

Slide 85

Slide 85 text

Use the WebP tool Specify compression

Slide 86

Slide 86 text

Use the WebP tool Specify compression Specify sharpness & size

Slide 87

Slide 87 text

Use the WebP tool Specify compression Specify sharpness & size Available for Win, Mac & Linux

Slide 88

Slide 88 text

Slide 89

Slide 89 text

JavaScript Shim https://github.com/antimatter15/weppy

Slide 90

Slide 90 text

JavaScript Shim https://github.com/antimatter15/weppy Client Side http://www.stucox.com/blog/using-webp-with-modernizr/

Slide 91

Slide 91 text

JavaScript Shim https://github.com/antimatter15/weppy Client Side http://www.stucox.com/blog/using-webp-with-modernizr/ Server Side http://tinyurl.com/BlogWebP

Slide 92

Slide 92 text

Give it a go! tinyurl.com/LeastWebP

Slide 93

Slide 93 text

Compressive Images

Slide 94

Slide 94 text

Compressive Concept..

Slide 95

Slide 95 text

Compressive Concept..

Slide 96

Slide 96 text

Compressive Concept..

Slide 97

Slide 97 text

Compressive Concept..

Slide 98

Slide 98 text

Compressive Concept..

Slide 99

Slide 99 text

Compressive Concept..

Slide 100

Slide 100 text

Compressive Concept..

Slide 101

Slide 101 text

Compressive Concept..

Slide 102

Slide 102 text

YDN says... “Don't Scale Images in HTML. Don't use a bigger image than you need just because you can set the width and height in HTML. If you need: My Cat then your image (mycat.jpg) should be 100x100px rather than a scaled down 500x500px image.”

Slide 103

Slide 103 text

Google says.. “Specify dimensions that match those of the images themselves. Don't use width and height specifications to scale images on the fly. If an image file is actually 60 x 60 pixels, don't set the dimensions to 30 x 30 in the HTML or CSS. If the image needs to be smaller, scale it in an image editor and set its dimensions to match”

Slide 104

Slide 104 text

Rationale 1. You don't want to download more bytes than necessary

Slide 105

Slide 105 text

Rationale 2. Browsers are bad at resizing images

Slide 106

Slide 106 text

Don’t download more bytes

Slide 107

Slide 107 text

Don’t download more bytes * From Daan Jobsis’ wonderful article @ http://tinyurl.com/retinarev

Slide 108

Slide 108 text

Don’t download more bytes Big image low quality = GOOD Small image high quality = BAD

Slide 109

Slide 109 text

Browsers are bad at resizing

Slide 110

Slide 110 text

* From Roy Tanck’s interesting study @ http://tinyurl.com/browserscaling Browsers are bad at resizing 150 images: 50 x 24bit pngs 50 x jpeg 50 x 8bit gif One page: images displayed at 100%

Slide 111

Slide 111 text

Browsers are bad at resizing 150 images: 50 x 24bit pngs 50 x jpeg 50 x 8bit gif * From Roy Tanck’s interesting study @ http://tinyurl.com/browserscaling One page: images displayed at 100% Duplicate page: images scaled to 61.5%

Slide 112

Slide 112 text

* From Roy Tanck’s interesting study @ http://tinyurl.com/browserscaling No difference whatsoever Browsers are bad at resizing

Slide 113

Slide 113 text

Is it good?

Slide 114

Slide 114 text

Is it good?

Slide 115

Slide 115 text

Support for Compressive Images

Slide 116

Slide 116 text

Support for Compressive Images Chrome

Slide 117

Slide 117 text

Support for Compressive Images Chrome All of them

Slide 118

Slide 118 text

Support for Compressive Images Chrome All of them Opera

Slide 119

Slide 119 text

Support for Compressive Images Chrome All of them Opera All of them

Slide 120

Slide 120 text

Support for Compressive Images Chrome All of them Opera All of them Firefox

Slide 121

Slide 121 text

Support for Compressive Images Chrome All of them Opera All of them Firefox All of them

Slide 122

Slide 122 text

Support for Compressive Images Chrome All of them Opera All of them Firefox All of them IE

Slide 123

Slide 123 text

Support for Compressive Images Chrome All of them Opera All of them Firefox All of them IE All of them

Slide 124

Slide 124 text

Support for Compressive Images Chrome All of them Opera All of them Firefox All of them IE All of them

Slide 125

Slide 125 text

Support for Compressive Images Chrome All of them Opera All of them Firefox All of them IE All of them* at least I think so...

Slide 126

Slide 126 text

Got ? Got Compressive

Slide 127

Slide 127 text

Give it a go! tinyurl.com/LeastCompressive

Slide 128

Slide 128 text

Data URIs

Slide 129

Slide 129 text

“The fastest HTTP request is the one not made.”

Slide 130

Slide 130 text

Every image in a web page is a new HTTP request

Slide 131

Slide 131 text

Data URIs are different

Slide 132

Slide 132 text

Funny Cat

Slide 133

Slide 133 text

Data URIs are embedded as a Base64 encoded string

Slide 134

Slide 134 text

Funny
Cat

Slide 135

Slide 135 text

Funny
Cat

Slide 136

Slide 136 text

Data URIs Embedded in a web page

Slide 137

Slide 137 text

Data URIs Embedded in a web page No HTTP request is made

Slide 138

Slide 138 text

Data URIs Embedded in a web page No HTTP request is made Faster load times

Slide 139

Slide 139 text

Data URIs Embedded in a web page No HTTP request is made Faster load times* *Sometimes

Slide 140

Slide 140 text

Support is great So....what’s the catch?

Slide 141

Slide 141 text

- Some browsers only support Data URIs up to a certain size

Slide 142

Slide 142 text

- Some browsers only support Data URIs up to a certain size - Base64 encoded strings are actually around a third larger than the original image size

Slide 143

Slide 143 text

- Some browsers only support Data URIs up to a certain size - Base64 encoded strings are actually around a third larger than the original image - Need to re-encode on every change

Slide 144

Slide 144 text

- Some browsers only support Data URIs up to a certain size - Base64 encoded strings are actually around a third larger than the original image - Need to re-encode on every change - Consume battery and CPU on mobile devices

Slide 145

Slide 145 text

Don’t worry!

Slide 146

Slide 146 text

- Images less than 32K - Great for icons Use it for:

Slide 147

Slide 147 text

Give it a go! tinyurl.com/LeastDataURI

Slide 148

Slide 148 text

The Future?

Slide 149

Slide 149 text

The Future?

Slide 150

Slide 150 text

The right image for the user

Slide 151

Slide 151 text

The right image for the user

Slide 152

Slide 152 text

srcset HTML attribute

Slide 153

Slide 153 text

my cat

Slide 154

Slide 154 text

My Cat

Slide 155

Slide 155 text

My Cat

Slide 156

Slide 156 text

My Cat

Slide 157

Slide 157 text

My Cat

Slide 158

Slide 158 text

My Cat

Slide 159

Slide 159 text

My Cat

Slide 160

Slide 160 text

My Cat

Slide 161

Slide 161 text

picture HTML Element

Slide 162

Slide 162 text

my cat

Slide 163

Slide 163 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 164

Slide 164 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 165

Slide 165 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 166

Slide 166 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 167

Slide 167 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 168

Slide 168 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 169

Slide 169 text

picture + srcset

Slide 170

Slide 170 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 171

Slide 171 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 172

Slide 172 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 173

Slide 173 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 174

Slide 174 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 175

Slide 175 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 176

Slide 176 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 177

Slide 177 text

cutekittyawww

Lookit the cuuute kitty awwww

Slide 178

Slide 178 text

HD SD Tiger & Cat: http://www.flickr.com/photos/doug88888/ Kitten: http://www.flickr. min-width: 45em tiger-HD.jpg 2x min-width: 18em cat-HD.jpg 2x min-width: 18em cat.jpg 1x kitten.jpg 1x kitten.jpg 2x min-width: 45em tiger.jpg 1x

Slide 179

Slide 179 text

image-set() CSS4 function

Slide 180

Slide 180 text

background-image: image-set( "cat.png" 1x, "cat-HD.png" 2x, "cat-print.png" 600dpi );

Slide 181

Slide 181 text

background-image: image-set( "cat.png" 1x, "cat-HD.png" 2x, "cat-print.png" 600dpi );

Slide 182

Slide 182 text

background-image: image-set( "cat.png" 1x, "cat-HD.png" 2x, "cat-print.png" 600dpi );

Slide 183

Slide 183 text

background-image: image-set( "cat.png" 1x, "cat-HD.png" 2x, "cat-print.png" 600dpi );

Slide 184

Slide 184 text

@media all{ #pictureElement{ background-image: image-set(kitten.jpg 1x, kitten-HD.jpg 2x); } } @media all and (min-width: 45em){ #pictureElement{ background-image: image-set(tiger.jpg 1x, tiger-HD.jpg 2x); } } @media all and (min-width: 18em){ #pictureElement{ background-image: image-set(cat.jpg 1x, cat.jpg 2x); } }

Slide 185

Slide 185 text

@media all{ #pictureElement{ background-image: image-set(kitten.jpg 1x, kitten-HD.jpg 2x); } } @media all and (min-width: 45em){ #pictureElement{ background-image: image-set(tiger.jpg 1x, tiger-HD.jpg 2x); } } @media all and (min-width: 18em){ #pictureElement{ background-image: image-set(cat.jpg 1x, cat.jpg 2x); } }

Slide 186

Slide 186 text

@media all{ #pictureElement{ background-image: image-set(kitten.jpg 1x, kitten-HD.jpg 2x); } } @media all and (min-width: 45em){ #pictureElement{ background-image: image-set(tiger.jpg 1x, tiger-HD.jpg 2x); } } @media all and (min-width: 18em){ #pictureElement{ background-image: image-set(cat.jpg 1x, cat.jpg 2x); } }

Slide 187

Slide 187 text

Your favourite?

Slide 188

Slide 188 text

Srcset Image-set Picture Element Multiple image dimensions Multiple image resolutions Reduces HTTP requests

Slide 189

Slide 189 text

Summary

Slide 190

Slide 190 text

Download the source code tinyurl.com/imageoptimiser

Slide 191

Slide 191 text

View the demos tinyurl.com/LeastDemos

Slide 192

Slide 192 text

@rposbo @deanohume