52
Chris Fetherston Keep the web fast

Keep the Web Fast

Embed Size (px)

Citation preview

Page 1: Keep the Web Fast

Chris FetherstonKeep the web fast

Page 2: Keep the Web Fast

1. Why

2. Optimization Guidelines

3. The Critical Rendering Path

4. The Interaction Lifecycle

5. Examples

Page 3: Keep the Web Fast

Chris Fetherston

Why does performance matter?

Page 4: Keep the Web Fast

Chris Fetherston

Fast performance = good user experience = more interactions = more conversions

Gestural interfaces require near instantaneous response to user input

Faster pages mean lower abandonment rates

Page 5: Keep the Web Fast

Chris Fetherston

Mobile traffic exceeds desktop

Mobile devices have lower processing power than desktop (but that’s changing)

Mobile devices generally have slower connections and limited bandwidth

Devices have gotten “lighter”

Page 6: Keep the Web Fast

Chris Fetherston

Browsers support richer experiences than ever

Publishers are pushing towards sites that force page views (think listicles)

Analytics, ad tech and tracking scripts are bloating our sites

But the web has gotten “heavier”

Page 7: Keep the Web Fast

Chris Fetherston

Example: cnn.com mobile

Page 8: Keep the Web Fast

Chris Fetherston

cnn.com mobile

228 Network requests

2.5 MB transfered

75 JS files, 6 CSS files, 101 images

32 Analytics, ads or tracking

Page 9: Keep the Web Fast

First some guidelines.

Page 10: Keep the Web Fast

Chris Fetherston

Measure your website or app continuously

Understand how a performance problem relates to your website or app

Fix problematic areas and measure again

Beware of added complexity

1. You can’t optimize what you can’t measure

Page 11: Keep the Web Fast

Measure. Understand. Fix.

Page 12: Keep the Web Fast

Chris Fetherston

2. Tools not rules

Page 13: Keep the Web Fast

Rules become unfounded dogma. Tools provide quantitative data in your app,

in your browser, on a real device.

Page 14: Keep the Web Fast

Chris Fetherston

A micro-benchmark is when only a small portion of code is measured

The code you write is not the code that runs in the browser

JavaScript engines do their own optimizations after parsing to avoid common bottlenecks

3. Avoid micro-benchmarks

Page 15: Keep the Web Fast

Boring! Let’s get started.

Page 16: Keep the Web Fast

The Critical Rendering Path

Page 17: Keep the Web Fast

Chris Fetherston

“The series of events that must take place to display the initial view of a webpage.”

-varv.com

What is the CRP?

Page 18: Keep the Web Fast

Chris Fetherston

What is the CRP?

DOWNLOAD HTML

DOWNLOAD & PARSE DEPS

RENDER

Page 19: Keep the Web Fast

Chris Fetherston

Prioritize your high-value pages

Use client analytics to sample latency across your user base (Network Performance API)

Identify problematic areas with the network tab in developer tools

Measure the CRP

Page 20: Keep the Web Fast

Chris Fetherston

Measure the CRP

Page 21: Keep the Web Fast

Chris Fetherston

Understand the CRP Using the timeline

Page 22: Keep the Web Fast

Chris Fetherston

Understand the CRP Request timing

Hello server? I need this.

Hi, let me get that for you.

Here, it is. Download it.

Page 23: Keep the Web Fast

Chris Fetherston

Understand the CRP Verify file size & compression

Size sent over the wire incl.

headers, cookies,etc

Actual file size

Page 24: Keep the Web Fast

Chris Fetherston

Understand the CRP Page load timing

The HTML document has

finished loadingAll dependencies

have finished loading

Page 25: Keep the Web Fast

Chris Fetherston

Verify server setup (minified, gzipped, combined assets where needed, cached)

CSS in the <head>, JS at the bottom of <body>

Prioritize above the fold content

Defer the rest

Fix the CRP

Page 26: Keep the Web Fast

Chris Fetherston

3,818 CSS rules served, 496 rules used (87% unused)

101 images served, 1 visible

All images and most JS scripts could be loaded on scroll or 1-2s after page load

Fix the CRP Prioritize above the fold content

Page 27: Keep the Web Fast

The Interaction Cycle

Page 28: Keep the Web Fast

Chris Fetherston

A framework for breaking down the stages of interaction as a user moves throughout an interface.

What is the Interaction Cycle?

Page 29: Keep the Web Fast

Chris Fetherston

1. Load New content is loaded and presented to the user

2. Idle User views content and decides next action

3. Respond Interface responds to user interaction

4. Animate Interface transitions to requested content

What is the Interaction Cycle?

Page 30: Keep the Web Fast

Chris Fetherston

Developer tools Timeline & Profiles

Client-side logging

Frames per second monitor

Measure the Interaction Cycle

Page 31: Keep the Web Fast

Chris Fetherston

Understand the Interaction Cycle Chrome Timeline

Page 32: Keep the Web Fast

Chris Fetherston

Understand the Interaction Cycle Chrome Timeline

Frames per second over time

We’ve blown over our FPS budget (Jank!)

Page 33: Keep the Web Fast

Chris Fetherston

Understand the Interaction Cycle Chrome Timeline

Functions invoked & time spent

Page 34: Keep the Web Fast

Chris Fetherston

Understand the Interaction Cycle Chrome Timeline

Slow function

Child processes

Page 35: Keep the Web Fast

Chris Fetherston

Fix the Interaction Cycle

Page 36: Keep the Web Fast

Chris Fetherston

Browser loads new content via AJAX or page load

Optimize content delivery (CRP if initial page load)

After content is loaded, use timeline to pin-point expensive JS operations

Fix the Interaction Cycle 1. Load

Page 37: Keep the Web Fast

Chris Fetherston

Time before user interacts with loaded assets

Est. 1.5-2s on average

Load deferred scripts, below the fold content, and non-essential images

Fix the Interaction Cycle 2. Idle

Page 38: Keep the Web Fast

Chris Fetherston

User interacts with page and the interface responds

100ms-200ms window to front load tasks before user perceives as latency

Prepare animations

Remove as much pressure off the CPU as possible for the next step

Fix the Interaction Cycle 3. Respond

Page 39: Keep the Web Fast

Chris Fetherston

New content renders to interface

Low budget, front load as much as possible

60fps = 16ms execution time per frame (even less including browser overhead)

requestAnimationFrame is your friend

Fix the Interaction Cycle 4. Animate

Page 40: Keep the Web Fast

Examples

Page 41: Keep the Web Fast

Chris Fetherston

Ghostlist

Library to remove content from the DOM when it scrolls off screen

Was this optimization worth the added complexity?

We verified perf gains by monitoring frames per second with timeline

…but we had some bugs with adblock, and content randomly disappearing

Page 42: Keep the Web Fast

So let’s test it!

Page 43: Keep the Web Fast

Chris Fetherston

Overall Queries -6%

Page 44: Keep the Web Fast

Chris Fetherston

Post Impressions -17%

Page 45: Keep the Web Fast

Chris Fetherston

Engagement -12%

Page 46: Keep the Web Fast

Chris Fetherston

Peepr

We call this thing that shows a blog inside your dashboard Peepr

Launched MVP with 6 second perceived load time

Identified some key network issues using network tab

Version 2 rewrite 900ms perceived load time

Page 47: Keep the Web Fast

Chris Fetherston

Peepr

We reduced the error rate by 7.5%

8% increase in opens at launch 3.8% increase in follows 6.2% increase in reblogs 13.5% increase in likes Opens grew nearly +12% over a month

Page 48: Keep the Web Fast

Let’s make a faster web, together.

Page 49: Keep the Web Fast

Chris Fetherston

If you’re an engineer

Be tenacious, set performance budgets and keep them

Build or buy the client-side tools needed

Make performance monitoring part of your workflow

Page 50: Keep the Web Fast

Chris Fetherston

If you’re a PM or Business Owner

Build time into your product development cycle to address performance issues

Know your app’s “Happy Path” and dedicate resources towards optimizing it

Do we really need another tracking script?

Page 51: Keep the Web Fast

Thank you.

Page 52: Keep the Web Fast

Stay fast, my friends.

@fetherston93 blog.cfetherston.com