Slide 1

Slide 1 text

Case study in making animations not suck

Slide 2

Slide 2 text

Mike Herchel Front-end Developer at Lullabot @mikeherchel

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Organization 1. Walk through
 2. How the browser renders webpages
 3. Front-end profiling tools
 4. Real-world applications

Slide 5

Slide 5 text

[Demo Time] Let’s check out www.Syfy.com

Slide 6

Slide 6 text

[Part 2] How browsers render content (a quickie)

Slide 7

Slide 7 text

Browser Rendering 1. Document Object Model 2. CSS Object Model 3. Render Tree & Layout 4. Painting 5. Compositing

Slide 8

Slide 8 text

Document Object Model Graphic(s) from https://developers.google.com

Slide 9

Slide 9 text

CSS Object Model Graphic(s) from https://developers.google.com

Slide 10

Slide 10 text

The Render Tree & Layout Graphic(s) from https://developers.google.com

Slide 11

Slide 11 text

Causes of Layout Invalidation (aka reflow) • Adding, removing, updating DOM nodes • Adding CSS classes • Height, width, margins, paddings, border-widths, display - basically anything that causes crap to get moved around the page. • Javascript Offsets also trigger a reflow because they they have to reconstruct the dom • Check out http://csstriggers.com

Slide 12

Slide 12 text

Layout Thrashing Examples from http://wilsonpage.co.uk/preventing-layout-thrashing

Slide 13

Slide 13 text

What doesn’t cause layout?

Slide 14

Slide 14 text

CSS Transforms!

Slide 15

Slide 15 text

Promote transform elements to own layer .my-awesome-div { will-change: transform, opacity; backface-visibility: hidden; }

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Compositing Layers Graphic(s) from http://www.chromium.org

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

tldr; ! 1. Be mindful of where you’re adding and removing classes 2. Use CSS Transforms instead of top, left, margins, etc 3. Promote layers when necessary

Slide 20

Slide 20 text

Profiling the front-end through Chrome DevTools (demo!) [Part 3]

Slide 21

Slide 21 text

In action [Part 4]

Slide 22

Slide 22 text

Don’t fight yourself!

Slide 23

Slide 23 text

Don’t fight yourself! (pt 2)

Slide 24

Slide 24 text

[Live Demos]

Slide 25

Slide 25 text

Want to learn more? • DOM: https://developers.google.com/web/fundamentals/performance/ critical-rendering-path/constructing-the-object-model?hl=en • Render Tree & Layout:! • http://gent.ilcore.com/2011/03/how-not-to-trigger-layout-in-webkit.html • http://www.html5rocks.com/en/tutorials/speed/layers/ • http://wilsonpage.co.uk/preventing-layout-thrashing/ • Painting & Compositing! • https://developers.google.com/web/fundamentals/performance/ rendering/stick-to-compositor-only-properties-and-manage-layer- count?hl=en • http://www.html5rocks.com/en/tutorials/speed/layers/ • http://www.chromium.org/developers/design-documents/gpu- accelerated-compositing-in-chrome • General! • http://jankfree.org/ • http://aerotwist.com/blog/pixels-are-expensive/

Slide 26

Slide 26 text

Thanks! Give me feedback at @mikeherchel Questions?