Slide 1

Slide 1 text

Practical Responsive Web Design JSDay 2013 Jonathan Klein, Performance Engineer @jonathanklein

Slide 2

Slide 2 text

Slides, Links jkle.in/jsday

Slide 3

Slide 3 text

Some Etsy Stats • Handmade marketplace • 1.4 billion page views/month • Almost $1B in sales last year • ~1M lines of JavaScript

Slide 4

Slide 4 text

Two Assertions

Slide 5

Slide 5 text

1. RWD isn’t that hard

Slide 6

Slide 6 text

2. RWD can be fast

Slide 7

Slide 7 text

The Basics

Slide 8

Slide 8 text

Building blocks of RWD /* Greater than 900px wide */ @media screen and (min-width: 56.25em) {...} ! /* Retina Display */ @media screen and (min-device-pixel-ratio: 2) {...} ! /* You can chain these */ @media screen and (min-width: 56.25em) and (min- device-pixel-ratio: 2) {...}

Slide 9

Slide 9 text

Building blocks of RWD /* Greater than 900px wide */ @media screen and (min-width: 56.25em) {...} ! /* Retina Display */ @media screen and (min-device-pixel-ratio: 2) {...} ! /* You can chain these */ @media screen and (min-width: 56.25em) and (min- device-pixel-ratio: 2) {...}

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Breakpoints

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

What Breakpoints to Use?

Slide 14

Slide 14 text

What Breakpoints to Use? • Don’t think about devices

Slide 15

Slide 15 text

What Breakpoints to Use? • Don’t think about devices • “Make it look good”

Slide 16

Slide 16 text

What Breakpoints to Use? • Don’t think about devices • “Make it look good” • Something like 600px, 900px, max

Slide 17

Slide 17 text

What Breakpoints to Use? • Don’t think about devices • “Make it look good” • Something like 600px, 900px, max • Divide by 16 to get em’s

Slide 18

Slide 18 text

Retina Images

Slide 19

Slide 19 text

Start With the Normal Version ! /* Small version of the logo */ .logo { background-image: url(logo_sm.png); background-repeat: no-repeat; background-position: center; background-size: 230px 50px; }

Slide 20

Slide 20 text

Start With the Normal Version ! /* Small version of the logo */ .logo { background-image: url(logo_sm.png); background-repeat: no-repeat; background-position: center; background-size: 230px 50px; }

Slide 21

Slide 21 text

High Res Screens ! ! ! ! /* Provide a hi-res logo for retina screens */ @media screen and (-webkit-min-device-pixel-ratio: 2) { .logo { background-image: url(logo_lg.png); } }

Slide 22

Slide 22 text

RWD In Action

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Clean up some CSS .article { width: 31%; min-width:250px; } ! #content .wrapper { width:auto; } ! #page { background:none; }

Slide 26

Slide 26 text

Make it Responsive /* Two articles across */ @media screen and (max-width: 850px) { .article { width: 46%; } } ! /* One article across */ @media screen and (max-width: 530px) { .article { width: 90%; } }

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Performance

Slide 29

Slide 29 text

A Few Considerations

Slide 30

Slide 30 text

A Few Considerations • Extra CSS (minimal)

Slide 31

Slide 31 text

A Few Considerations • Extra CSS (minimal) • Retina Images (ouch)

Slide 32

Slide 32 text

A Few Considerations • Extra CSS (minimal) • Retina Images (ouch) • Larger images than needed

Slide 33

Slide 33 text

A Few Considerations • Extra CSS (minimal) • Retina Images (ouch) • Larger images than needed • Extra Image Requests

Slide 34

Slide 34 text

A Few Considerations • Extra CSS (minimal) • Retina Images (ouch) • Larger images than needed • Extra Image Requests

Slide 35

Slide 35 text

Responsive Images

Slide 36

Slide 36 text

Three Performance Goals:

Slide 37

Slide 37 text

Three Performance Goals: 1. Start with a small image

Slide 38

Slide 38 text

Three Performance Goals: 1. Start with a small image 2. Upgrade to larger size without downloading both

Slide 39

Slide 39 text

Three Performance Goals: 1. Start with a small image 2. Upgrade to larger size without downloading both 3. Unique image URLs (caching)

Slide 40

Slide 40 text

• Resize on the fly • Compress automatically First Step: Automation

Slide 41

Slide 41 text

Lossless Compression

Slide 42

Slide 42 text

140 KB Lossless Compression

Slide 43

Slide 43 text

140 KB 85 KB Lossless Compression

Slide 44

Slide 44 text

140 KB 85 KB Lossless Compression • http://www.smushit.com/ysmush.it/ • https://developers.google.com/speed/pagespeed/

Slide 45

Slide 45 text

• Automate HTML output • Plan for the future More Automation

Slide 46

Slide 46 text

HTML Output (picturefill)

Slide 47

Slide 47 text

HTML Output (picturefill) • https://github.com/scottjehl/picturefill

Slide 48

Slide 48 text

HTML Output (picturefill) • https://github.com/scottjehl/picturefill • Mimics proposed element

Slide 49

Slide 49 text

HTML Output (picturefill) • https://github.com/scottjehl/picturefill • Mimics proposed element • < 0.5K JS file

Slide 50

Slide 50 text

HTML Output (picturefill) • https://github.com/scottjehl/picturefill • Mimics proposed element • < 0.5K JS file • Supports all media queries

Slide 51

Slide 51 text

HTML Output (picturefill) • https://github.com/scottjehl/picturefill • Mimics proposed element • < 0.5K JS file • Supports all media queries • Works across all browsers

Slide 52

Slide 52 text

! Interesting Image Alt Text

Slide 53

Slide 53 text

! Interesting Image Alt Text
IE 6, 7, 8 get this

Slide 54

Slide 54 text

How does it do?

Slide 55

Slide 55 text

How does it do? ✓ Unique image URLs

Slide 56

Slide 56 text

How does it do? ✓ Unique image URLs ✓ Start with smallest image

Slide 57

Slide 57 text

How does it do? ✓ Unique image URLs ✓ Start with smallest image ✓ Only one image download

Slide 58

Slide 58 text

How does it do? ✓ Unique image URLs ✓ Start with smallest image ✓ Only one image download ✓ Fallback for old IE

Slide 59

Slide 59 text

But that markup...

Slide 60

Slide 60 text

Plan to Replace Whatever You Build

Slide 61

Slide 61 text

Resources for Responsive Imgs Jason Grigsby: ! http://blog.cloudfour.com/responsive-imgs/ http://blog.cloudfour.com/responsive-imgs-part-2/ http://blog.cloudfour.com/responsive-imgs-part-3-future-of-the-img-tag/ http://blog.cloudfour.com/8-guidelines-and-1-rule-for-responsive-images/ http://blog.cloudfour.com/sensible-jumps-in-responsive-image-file-sizes/

Slide 62

Slide 62 text

Don’t type, click: jkle.in/jsday

Slide 63

Slide 63 text

Browser Support

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Fail

Slide 66

Slide 66 text

Handle IE Conditional Comments http://adactio.com/journal/4494/ ! ! More: http://buildmobile.com/understanding-responsive-web- design-cross-browser-compatibility/

Slide 67

Slide 67 text

The Future: Client Hints

Slide 68

Slide 68 text

Proposal by Ilya Grigorik

Slide 69

Slide 69 text

Proposal by Ilya Grigorik • Client (browser) sends an additional HTTP Header

Slide 70

Slide 70 text

Proposal by Ilya Grigorik • Client (browser) sends an additional HTTP Header • CH: dh=598, dw=384, dpr=2.0, t

Slide 71

Slide 71 text

Proposal by Ilya Grigorik • Client (browser) sends an additional HTTP Header • CH: dh=598, dw=384, dpr=2.0, t • https://github.com/igrigorik/http-client-hints/

Slide 72

Slide 72 text

Homework

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

Find your favorite non-responsive site

Slide 75

Slide 75 text

Find your favorite non-responsive site

Slide 76

Slide 76 text

Find your favorite non-responsive site Save the HTML locally

Slide 77

Slide 77 text

Find your favorite non-responsive site Save the HTML locally

Slide 78

Slide 78 text

Find your favorite non-responsive site Save the HTML locally Add some media queries and a breakpoint

Slide 79

Slide 79 text

Find your favorite non-responsive site Save the HTML locally Add some media queries and a breakpoint

Slide 80

Slide 80 text

Find your favorite non-responsive site Save the HTML locally Add some media queries and a breakpoint Make one retina image and use it

Slide 81

Slide 81 text

Find your favorite non-responsive site Save the HTML locally Add some media queries and a breakpoint Make one retina image and use it

Slide 82

Slide 82 text

Welcome to the world of RWD

Slide 83

Slide 83 text

• Resize browser window, use console when you want a breakpoint • document.body.offsetWidth • If you must start w/ desktop, use: • @media screen and (max-width: 900px) { Some Hints

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

Recap

Slide 86

Slide 86 text

Recap • Start with small sizes on new sites

Slide 87

Slide 87 text

Recap • Start with small sizes on new sites • Use em’s and %’s

Slide 88

Slide 88 text

Recap • Start with small sizes on new sites • Use em’s and %’s • ~3-4 device independent breakpoints

Slide 89

Slide 89 text

Recap • Start with small sizes on new sites • Use em’s and %’s • ~3-4 device independent breakpoints • Use Responsive Images

Slide 90

Slide 90 text

Recap • Start with small sizes on new sites • Use em’s and %’s • ~3-4 device independent breakpoints • Use Responsive Images • Have a fallback plan for IE

Slide 91

Slide 91 text

Get in Touch ! www.etsy.com/careers ! jonathan@etsy.com ! @jonathanklein