Optimizing web performance (Fronteers edition)

67
Optimizing Web Performance Dave Olsen, @dmolsen West Virginia University http://flic.kr/p/7A8xxN

description

Today, a web page can be delivered to desktop computers, televisions, or handheld devices like tablets or phones. While a technique like responsive design helps ensure that our web sites look good across that spectrum of devices we may forget that we need to make sure that our web sites also perform well across that same spectrum. More and more of our users are shifting their Internet usage to these more varied platforms and connection speeds with some moving entirely to mobile Internet. In this session we’ll look at the tools that can help you understand, measure and improve the web performance of your web sites and applications. The talk will also discuss how new server-side techniques might help us optimize our front-end performance. Finally, since the best way to test is to have devices in your hand, we’ll discuss some tips for getting your hands on them cheaply.

Transcript of Optimizing web performance (Fronteers edition)

Page 1: Optimizing web performance (Fronteers edition)

OptimizingWeb PerformanceDave Olsen, @dmolsenWest Virginia University

http://flic.kr/p/7A8xxN

Page 2: Optimizing web performance (Fronteers edition)

What I’ll Talk About

• Quick Intro About Why We Should Care About Web Perf

• Diagnosing Perf Problems

• Easy Web Performance Optimization Wins

• Tools to Help Test & Automate Perf Optimizations

• Setting Up a Device Lab

Page 3: Optimizing web performance (Fronteers edition)

WHY SHOULD WE CARE ABOUT WEB PERFORMANCE?

http://flic.kr/p/4JY1Yr

Page 4: Optimizing web performance (Fronteers edition)

brad’s iceberg

© Brad Frost

© Brad Frost

Page 5: Optimizing web performance (Fronteers edition)

The way in which CSS media queries have been promoted for

mobile hides tough problems and gives developers a false promise of a simple solution for designing

for small screens.

Source: Jason Grigsby on Speakerdeck

- Jason Grigsby, @grigs

Page 6: Optimizing web performance (Fronteers edition)

brad’s iceberg

© Brad Frost© Brad Frost

© Brad Frost

Page 7: Optimizing web performance (Fronteers edition)

The average weight of a web page today:

Source: HTTP Archive

Images JavaScript

Flash

HTM

LC

SSOther

78%

1.8 MB

Page 8: Optimizing web performance (Fronteers edition)

RWD sites whose small screen design weighs the same as the large screen design.Source: Podjarny, 2013

72%

Page 10: Optimizing web performance (Fronteers edition)

Bounce Rate Conversion Rate Cart Size Page Views

200ms - - - -1.2%

500ms -4.7% -1.9% - -5.7%

1000ms -8.3% -3.5% -2.1% -9.4%

CASE STUDY: MOBILE PERFORMANCE EFFECT ON BUSINESS

Source: Web Performance Today

Page 11: Optimizing web performance (Fronteers edition)

Mobile first means performance first.

Page 12: Optimizing web performance (Fronteers edition)

Over Downloading

Download & HideDownload & ShrinkDownload & Ignore

PRIMARY PERFORMANCE ISSUES FOR RWD

Poor Networks

High LatencyVariable Bandwidth

Packet Loss

Page 13: Optimizing web performance (Fronteers edition)

Current Dev Practices + Desktop First RWD

Web Performance Blues

REVIEWING WHY WE SHOULD CARE

Page 14: Optimizing web performance (Fronteers edition)

sad face

https://flic.kr/p/9g5Gg8

Page 15: Optimizing web performance (Fronteers edition)

https://flic.kr/p/6DBSCi

DIAGNOSING WEB PERFORMANCE ISSUES

Page 16: Optimizing web performance (Fronteers edition)

THE BASICS: PAGESPEED INSIGHTSdevelopers.google.com/speed/pagespeed/insights

Page 17: Optimizing web performance (Fronteers edition)

NEXT STEPS: CHROME DEV TOOLSdev tools is more than just the elements view!

Page 18: Optimizing web performance (Fronteers edition)

NEXT STEPS: CHROME DEV TOOLS COURSEudacity.com/course/ud884/

Page 19: Optimizing web performance (Fronteers edition)

DEEP CUTS: WEBPAGETESTwww.webpagetest.org

Page 20: Optimizing web performance (Fronteers edition)

DEEP CUTS: WEBPAGETESTnote the big red F :(

Page 21: Optimizing web performance (Fronteers edition)

WEBPAGETEST FEATURES

• Test real browsers from mult. locations• Modify connection speeds• Video capture• Content blocking• Script the session• Use with continuous integration• Collect tests over time• Free

Page 22: Optimizing web performance (Fronteers edition)

REVIEW OF DIAGNOSTIC TOOLS

• Fast & easy? Pagespeed Insights• Local development? Chrome Dev Tools• Customization? WebPagetest

Page 23: Optimizing web performance (Fronteers edition)

http://flic.kr/p/4zzKee

easy web performance optimization wins

EASY WEB OPTIMIZATION WINS

https://flic.kr/p/nYDzXn

Page 24: Optimizing web performance (Fronteers edition)

Performance

http://timkadlec.com/2013/01/setting-a-performance-budget/http://flic.kr/p/7BBs6e

A budget is a guide, not a hard & fast limit. Performance tweaks are compromises.

Page 25: Optimizing web performance (Fronteers edition)

MOBILE OPTIMIZATION TENETS

1. Reduce requests2.Reduce asset size3. Speed-up page render

http://flic.kr/p/4zzKee

Page 26: Optimizing web performance (Fronteers edition)

Best request is no request.

Source: Ilya Grigorik

- Ilya Grigorik, @ilyagrigorik

Page 27: Optimizing web performance (Fronteers edition)

WEB PERF & SERVER-SIDE: EASY WINS

Compress HTML & CSS

If you’re using Apache make sure to use mod_deflate so text-based assets are compressed for transfer.

Browser cache

The simplest way to reduce requests is to make sure the browser doesn’t need to make them. Make sure assets are bring cached on the browser. Try redbot.org to see if you’re caching.

Avoid AJAX requests

Think critically about how you use AJAX. You may be able to increase perceived performance by “caching” mark-up in script tags.

Page 28: Optimizing web performance (Fronteers edition)

WEB PERFORMANCE & IMAGES: EASY WINS

Try to avoid images

When possible think about avoiding images. Implement with CSS or Canvas. Or use SVG or Progressive JPEGs.

Image compression

Choose appropriate image formats and compress within reason. Consider using CSS sprites.

Responsive images

Use srcset to serve regular images. You can use picture to serve art directed responsive images.

Avoid dark matter

display: none; hides content. It doesn’t stop content from loading. Properly set media queries.

Page 29: Optimizing web performance (Fronteers edition)

WEB PERF & IMAGES: TOOLS

Grunt & Gulp Tools

imagemin, image-resize, spritesmith, svgmin

On the Web kraken.io, smushit.com, spriteme.org, imigix.com

Page 30: Optimizing web performance (Fronteers edition)

CDNs Consider using CDNs to serve common JS libraries to help reduce RTT for requests.

WEB PERF & JAVASCRIPT: EASY WINS

MicroJS or, even better,

Vanilla JS

Avoid using bulky frameworks if you’re using them for simple tasks like selectors. Try microjs.com to find libraries that may be smaller & more suitable. JavaScript also blocks the rendering of the page.

Use Touch or FastClick

While not directly related to page render, by making sure your links use a Touch event or FastClick rather than an onClick event user interactions will speed up by 300ms.

Avoid DOM reflows &

repaints

By using JS to modify the DOM you can cause unnecessary reflows & repaints of your browser. They slow down page render time as well as burn battery.

Page 31: Optimizing web performance (Fronteers edition)

WEB PERF & JAVASCRIPT: TOOLS

Grunt & Gulp Tools

uglify, concat, closure-compiler, google-cdn

On the Web microjs.com, developer.mozilla.org,developers.google.com

Page 32: Optimizing web performance (Fronteers edition)

CONTENT BREAKDOWN

Page 33: Optimizing web performance (Fronteers edition)

WEB PERF & 3rd PARTY CODE: EASY WINS

Beware the SPOF

Be careful regarding what 3rd-party code you use on your pages. Downtime for them can mean slow loading pages for you. Try using spof-o-matic in the Chrome Web Store to see how your page is affected.

Avoid SM widgets

Try using simple links to services rather than utilizing their JavaScript widgets. They’re performance hogs. Removing the widgets also increases user privacy. 2-click social widgets from Heise is a good solution.

Page 34: Optimizing web performance (Fronteers edition)

TESTING SPOF

Page 35: Optimizing web performance (Fronteers edition)

Worst request is one that blocks the parser.

Source: Ilya Grigorik

- Ilya Grigorik, @ilyagrigorik

Page 36: Optimizing web performance (Fronteers edition)

Image source: https://developers.google.com/web/fundamentals/performance/critical-rendering-path/

THE CRITICAL RENDERING PATH

Page 37: Optimizing web performance (Fronteers edition)

LEARN TO LOVE THE WATERFALL

Page 38: Optimizing web performance (Fronteers edition)

LEARN TO LOVE THE WATERFALL

onload

start render

domcontentloaded

Page 39: Optimizing web performance (Fronteers edition)

CRITICAL RENDERING PATH: FILMSTRIP VIEW

Page 40: Optimizing web performance (Fronteers edition)

CRITICAL RENDERING PATH: % COMPLETE

Page 41: Optimizing web performance (Fronteers edition)

CRITICAL RENDERING PATH: EASY WINS

Defer loading of

JavaScript

Place script elements just above the body tag. Otherwise use HTML5’s script defer & async attributes to avoid blocking the parser. Can also insert script elements into the DOM using the onload event.

Inline Critical CSS

& Defer Rest

Place critical CSS directly within your document and load the rest of the CSS after onload with JavaScript. Use a service like Penthouse to find critical CSS.

Same DNS origin

Above the fold elements should be on the same hostname. Reduces DNS look-ups. Possible to try for a single request for all above the fold content?

Page 42: Optimizing web performance (Fronteers edition)

The ultimate goal is a narrower, shorter waterfall. Also focus on

getting a fast initial render.

Page 43: Optimizing web performance (Fronteers edition)

http://flic.kr/p/bMdzZ2

TEST THE SQUISHY

default styles vs. min-width vs. max-width

Page 44: Optimizing web performance (Fronteers edition)

SCRIPTING & CUSTOM VIEWPORTS

Page 45: Optimizing web performance (Fronteers edition)

SCRIPTING & CUSTOM VIEWPORTS

Page 47: Optimizing web performance (Fronteers edition)

REVIEWING TOP TIPS FOR EASY WINS

• Budget to give yourself and a client a performance goal

• Enable cache headers• Enable compression • Properly format or reduce images• Defer as much as you can • Use a task runner to build web

performance into your workflow

Page 48: Optimizing web performance (Fronteers edition)

RESS can be a scalpel for your responsive designs.

REsponsive Design + Server Side Components

http

://fli

c.kr

/p/a

4VsP

v

Page 49: Optimizing web performance (Fronteers edition)

RESS: AN EVOLUTION OF RESPONSIVE DESIGN

slidesha.re/KtByzQit is not an “evolution” but just another tool

Page 50: Optimizing web performance (Fronteers edition)

Testing Tools

toolbox, tools

MORE WEB PERFORMANCE TOOLS

http://flic.kr/p/4BZsQJ

Page 51: Optimizing web performance (Fronteers edition)

LIST OF PERF TOOLSperf-tooling.today

Page 52: Optimizing web performance (Fronteers edition)

Google Analytics Site Speed

GOOGLE ANALYTICS’ SITE SPEED

Page 53: Optimizing web performance (Fronteers edition)

PERFORMANCE MONITORINGspeedcurve.com

Page 54: Optimizing web performance (Fronteers edition)

PERFMAP (alpha)github.com/zeman/perfmap

Page 55: Optimizing web performance (Fronteers edition)

REAL USER TESTINGyahoo.github.io/boomerang/doc/

Page 56: Optimizing web performance (Fronteers edition)

MOD_PAGESPEED: PERF AUTOMATIONdevelopers.google.com/speed/pagespeed/mod

  add_head  combine_css   convert_jpeg_to_progressive   convert_meta_tags   extend_cache   flatten_css_imports   inline_css   inline_import_to_link   inline_javascript   rewrite_css   rewrite_images   rewrite_javascript   rewrite_style_attributes_with_url

Default Filters

Page 57: Optimizing web performance (Fronteers edition)

DEVICES

http://flic.kr/p/cfkZhN

Page 58: Optimizing web performance (Fronteers edition)

REMOTE DEBUGGING

Page 59: Optimizing web performance (Fronteers edition)

charlesproxy.com

SLOWING THINGS DOWN

NLCCharles

Page 60: Optimizing web performance (Fronteers edition)

USING CHARLES PROXYblog.cloudfour.com/using-charles-proxy-to-examine-ios-apps/

Page 61: Optimizing web performance (Fronteers edition)

eBay MobileKarma.com Cellphone store leftoversOpen device labs

GET YOUR HANDS ON REAL DEVICES

http://flic.kr/p/7972f6

Page 62: Optimizing web performance (Fronteers edition)

OPENDEVICELAB.COM

Page 63: Optimizing web performance (Fronteers edition)

SUMMING IT ALL UP

• Open conversations using a performance budget

• First render speed is more important than pure resource size

• Integrate perf into your workflow• Test, evaluate, and monitor

Page 64: Optimizing web performance (Fronteers edition)

WEB PERF TWEEPS TO FOLLOW

@ilyagrigorik

@andydavies

@souders

@patmeenan

@stoyanstefanov

@bbinto

@scottjehl

just a sampling

@tameverts

Page 65: Optimizing web performance (Fronteers edition)

Dave OlsenProfessional TechnologistWest Virginia University

@dmolsen

THANKS FOR LISTENING

Page 66: Optimizing web performance (Fronteers edition)

QUESTIONS?

Page 67: Optimizing web performance (Fronteers edition)

Dave OlsenProfessional TechnologistWest Virginia University

@dmolsen

THANKS AGAIN FOR LISTENING