high performance web sites 14 rules for faster pages steve souders chief performance yahoo!...

61
High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! [email protected]

Upload: cody-oliver

Post on 26-Mar-2015

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

High Performance Web Sites

14 rules for faster pages

Steve SoudersChief Performance Yahoo!

[email protected]

Page 2: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Exceptional Performance

quantify and improve the performance of all Yahoo! products worldwide

center of expertise

build tools, analyze data

gather, research, and evangelize best practices

Page 3: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Scope

performance breaks into two categories– response time– efficiency

current focus is response time

of web products

coming up next: mobile, backend

Page 4: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

The Importance of Frontend Performance

Backend =

5%

Frontend =

95%

Even primed cache, frontend = 88%

Page 5: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Time Spent on the FrontendEmpty Cache

Primed Cache

amazon.com 82% 86%

aol.com 94% 86%

cnn.com 81% 92%

ebay.com 98% 92%

google.com 86% 64%

msn.com 97% 95%

myspace.com 96% 86%

wikipedia.org 80% 88%

yahoo.com 95% 88%

youtube.com 97% 95%

Page 6: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

The Performance Golden Rule

80-90% of the end-user response time is spent on the frontend. Start there.

• Greater potential for improvement

• Simpler

• Proven to work

Page 7: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Agenda

Performance Research

14 Rules (plus more)

Case Studies

Evangelism

Live Analysis

Page 8: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Performance Research

Page 9: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Browser Cache Experiment

Add an image to the page: Expires: Thu, 15 Apr 2004 20:00:00 GMT

Last-Modified: Wed, 28 Sep 2006 23:49:57 GMT

# users with at least one 200 response

total # unique users

Percentage of users with an empty cache?

Percentage of page views with an empty

cache?

# of 200 responses

total # responses

Page 10: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

0.0%

10.0%

20.0%

30.0%

40.0%

50.0%

60.0%

70.0%

80.0%

90.0%

100.0%

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

day of experiment

perc

enta

ge

unique users with empty cache

page views with empty cache

Browser Cache Expt Results

page views with

empty cache

40-60% ~20%

users withempty cache

Page 11: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Experiment Takeaways

The empty cache user experience is more prevalent than you think!

Optimize for both primed cache and empty cache experience.

Page 12: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Impact of Cookies on Response Time

80 ms delay dialup users

Cookie Size

Time Delta

0 bytes 78 ms 0 ms

500 bytes 79 ms +1 ms

1000 bytes 94 ms +16 ms

1500 bytes 109 ms +31 ms

2000 bytes 125 ms +47 ms

2500 bytes 141 ms +63 ms

3000 bytes 156 ms +78 ms

keep sizes low

Page 13: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Experiment Takeaways

eliminate unnecessary cookies

keep cookie sizes low

set cookies at appropriate domain level

set Expires date appropriately– earlier date or none removes cookie

sooner

Page 14: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

0 0.2 0.4 0.6 0.8 1 1.2 1.4

componentcomponentcomponentcomponentcomponentcomponentcomponentcomponentcomponentcomponent

html

0 0.2 0.4 0.6 0.8 1 1.2 1.4

componentcomponentcomponentcomponentcomponentcomponentcomponentcomponentcomponentcomponent

html

Two in parallel

Four in parallel

Eight in parallel

0 0.2 0.4 0.6 0.8 1 1.2 1.4

componentcomponentcomponentcomponentcomponentcomponentcomponentcomponentcomponentcomponent

html

Parallel Downloads

Page 15: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Maximizing Parallel Downloads

response time (seconds)

aliases

0.00

0.20

0.40

0.60

0.80

1.00

1.20

1.40

1 2 4 5 10

36 x 36 px (0.9 Kb) 116 x 61 px (3.4 Kb)

Page 16: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Maximizing Parallel Downloads

response time (seconds)

aliases

0.00

0.20

0.40

0.60

0.80

1.00

1.20

1.40

1 2 4 5 10

average 36 x 36 px (0.9 Kb) 116 x 61 px (3.4 Kb)

rule of thumb: use at least two but no more than four aliases

Page 17: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Experiment Takeaways

consider the effects of CPU thrashing

DNS lookup times vary across ISPs and geographic locations

domain names may not be cached

Page 18: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

14 Rules14 Rules

Page 19: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

14 Rules1. Make fewer HTTP requests2. Use a CDN3. Add an Expires header4. Gzip components5. Put stylesheets at the top6. Move scripts to the bottom7. Avoid CSS expressions8. Make JS and CSS external9. Reduce DNS lookups10. Minify JS11. Avoid redirects12. Remove duplicate scripts13. Configure ETags14. Make AJAX cacheable

Page 20: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 1: Make fewer HTTP requests

CSS sprites

combined scripts, combined stylesheets

preloading

image maps

inline images

Page 21: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

CSS Sprites

size of combined image is less

http://alistapart.com/articles/sprites

<span style="

background-image: url('sprites.gif');

background-position: -260px -90px;">

</span>

Page 22: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Combined Scripts, Combined Stylesheets

Scripts Stylesheets

amazon.com 3 1

aol.com 18 1

cnn.com 11 2

ebay.com 7 2

froogle.google.com 1 1

msn.com 9 1

myspace.com 2 2

wikipedia.org 3 1

yahoo.com 4 1

youtube.com 7 3

Average 6.5 1.5

Page 23: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Combined Scripts,Combined Stylesheets

combining six scripts into one eliminates five HTTP requests

challenges: – develop as separate modules– number of possible combinations vs.

loading more than needed– maximize browser cache

one solution:– dynamically combine and cache

Page 24: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Preloading

Download resources for the next page after the current page is done loading.

Examples:– http://www.google.com– http://search.yahoo.com

Page 25: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 2: Use a CDN

distribute your static content before distributing your dynamic content

amazon.com Akamai

aol.com Akamai

cnn.com

ebay.com Akamai, Mirror Image

google.com

msn.com SAVVIS

myspace.com Akamai, Limelight

wikipedia.org

yahoo.com Akamai

youtube.com

Page 26: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 2: Use a CDN

Adding your CDN(s) to YSlow– Go to about:config– Right-click in the window and choose New and

String to create a new string preference.– Enter extensions.firebug.yslow.cdnHostnames

for the preference name.– For the string value, enter the hostname of

your CDN, for example, mycdn.com.– Do not use quotes. If you have multiple CDN

hostnames, separate them with commas.

Page 27: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 3: Add an Expires header not just for images

Images

Stylesheets

Scripts

% with

Expires

Median Age

amazon.com 0/62 0/1 0/3 0% 114 days

aol.com 23/43 1/1 6/18 48% 217 days

cnn.com 0/138 0/2 2/11 1% 227 days

ebay.com 16/20 0/2 0/7 55% 140 days

froogle.google.com

1/23 0/1 0/1 4% 454 days

msn.com 32/35 1/1 3/9 80% 34 days

myspace.com 0/18 0/2 0/2 0% 1 day

wikipedia.org 6/8 1/1 2/3 75% 1 day

yahoo.com 23/23 1/1 4/4 100% n/a

youtube.com 0/32 0/3 0/7 0% 26 days

Page 28: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 4: Gzip components

you can affect users' download times

90%+ of browsers support compression

Page 29: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Gzip: not just for HTMLHTML Scripts Stylesheet

s

amazon.com x

aol.com x some some

cnn.com

ebay.com x

froogle.google.com

x x x

msn.com x deflate deflate

myspace.com x x x

wikipedia.org x x x

yahoo.com x x x

youtube.com x some somegzip scripts, stylesheets, XML, JSON (not images, PDF)

Page 30: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 5: Put stylesheets at the top

stylesheets block rendering in IE

solution: put stylesheets in HEAD (per spec)

avoids Flash of Unstyled Content

use LINK (not @import)

Page 31: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 6: Move scripts to the bottom

scripts block parallel downloads across all hostnames

scripts block rendering of everything below them in the page

script defer attribute is not a solution– blocks rendering and downloads in FF– slight blocking in IE

Page 32: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 7: Avoid CSS expressions

used to set CSS properties dynamically in IEwidth: expression( document.body.clientWidth < 600 ? “600px” : “auto” );

problem: expressions execute many times– mouse move, key press, resize, scroll, etc.

alternatives:– one-time expressions– event handlers

Page 33: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 8: Make JS and CSS external

inline: HTML document is bigger

external: more HTTP requests, but cached

variables– page views per user (per session)– empty vs. primed cache stats– component re-use

external is typically better

extra credit: post-onload download, dynamic inlining

Page 34: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Post-Onload Download

inline in front page

download external files after onloadwindow.onload = downloadComponents;function downloadComponents() { var elem = document.createElement("script"); elem.src = "http://.../file1.js"; document.body.appendChild(elem); ...}

speeds up secondary pages

Page 35: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Dynamic Inlining

start with post-onload download

set cookie after components downloaded

server-side: – if cookie, use external– else, do inline with post-onload

download

cookie expiration date is key

speeds up all pages

Page 36: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 9: Reduce DNS lookups

typically 20-120 ms

block parallel downloads

OS and browser both have DNS caches

Page 37: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Adding DNS Lookups

Increasing parallel downloads is worth an extra DNS lookup.

Page 38: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

minify inline scripts, too

Rule 10: Minify JavaScriptMinify

External?Minify Inline?

www.amazon.com

no no

www.aol.com no no

www.cnn.com no no

www.ebay.com yes no

froogle.google.com

yes yes

www.msn.com yes yes

www.myspace.com

no no

www.wikipedia.org

no no

www.yahoo.com yes yes

www.youtube.com

no no

Page 39: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 11: Avoid redirects

3xx status codes – mostly 301 and 302HTTP/1.1 301 Moved PermanentlyLocation: http://stevesouders.com/newuri

add Expires headers to cache redirects

worst form of blocking

Page 40: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 12: Remove duplicate scripts

hurts performance– extra HTTP requests (IE only)– extra executions

atypical?– 2 of 10 top sites contain duplicate

scripts

team size, # of scripts

Page 41: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 13: Configure ETags

unique identifier returned in responseETag: "c8897e-aee-4165acf0"Last-Modified: Thu, 07 Oct 2004 20:54:08 GMT

used in conditional GET requestsIf-None-Match: "c8897e-aee-4165acf0"If-Modified-Since: Thu, 07 Oct 2004 20:54:08 GMT

if ETag doesn't match, can't send 304ETag format

– Apache: inode-size-timestamp– IIS: Filetimestamp:ChangeNumber

Use 'em or lose 'em– Apache: FileETag none– IIS: http://support.microsoft.com/kb/922703/

Page 42: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Rule 14: Make AJAX cacheable

XHR, JSON, iframe, dynamic scripts can still be cached (and minified, and gzipped)

a personalized response should still be cacheable for that person

Page 43: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

AJAX Example: Yahoo! Mail Beta

address book XML request→ GET /yab/[...]&r=0.5289571053069156 HTTP/1.1 Host: us.xxx.mail.yahoo.com← HTTP/1.1 200 OK Date: Thu, 12 Apr 2007 19:39:09 GMT Cache-Control: private,max-age=0 Last-Modified: Sat, 31 Mar 2007 01:17:17 GMT Content-Type: text/xml; charset=utf-8 Content-Encoding: gzip

address book changes infrequently– cache it; add last-modified-time in URL

Page 44: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Next Rules• Split static content across multiple domains• Reduce the size of cookies• Host static content on a different domain• Minify CSS• Avoid IFrames

Page 45: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Case Studies

Page 46: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Case Study:

move JS to onloadremove bottom tabsavoid redirectsimage spriteshost JS on CDNcombine JS files

1/ 25/ 06 3/ 25/ 07

40-50%40-50%

Page 47: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

What about performance and Web 2.0 apps?

client-side CPU is more of an issue

user expectations are higher

these rules still apply, new rules will come out

start off on the right foot

Page 48: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Case Study:

User Workflow

mail.yahoo.com

view inbox folder

read messages (x3)

compose message

confirm send

total time:

Time

2.40 s

4.98 s

6.39 s

2.21 s

2.10 s

18.08 s

Time

12.48 s

1.52 s

1.53 s

0.34 s

0s

15.87 s

Delta

+420%

-70%

-76%

-85%

-100%

-12%

Mail

Mail

Mail Classic

Mail Classic

Page 49: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Evangelism

Page 50: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Evangelism

BookHigh Performance Web Sites

ConferencesYahoo! F2E SummitWeb 2.0 ExpoRich Web Experience

BlogsYUI Blog: http://yuiblog.com/blog/category/performance

YDN Blog: http://developer.yahoo.com/performance/

Open Source YSlow

OSConAjax ExperienceBlogherFuture of Web Apps

Page 51: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

YSlow

http://developer.yahoo.com/yslow

performance lint tool

scores web pages for each rule

Firefox add-on integrated with Firebug

open source license

Page 52: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com
Page 53: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Ten Top U.S Web Sites

Page Weight

Response Time

YSlow Grade

www.amazon.com 405K 15.9 sec D

www.aol.com 182K 11.5 sec F

www.cnn.com 502K 22.4 sec F

www.ebay.com 275K 9.6 sec C

froogle.google.com 18K 1.7 sec A

www.msn.com 221K 9.3 sec F

www.myspace.com 205K 7.8 sec D

www.wikipedia.org 106K 6.2 sec C

www.yahoo.com 178K 5.9 sec A

www.youtube.com 139K 9.6 sec D

Page 54: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Strong Correlation

total page weightresponse time

inverse YSlow grade

correlation(resp time, page weight) = 0.94correlation(resp time, inverse YSlow) = 0.76

Page 55: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Live Analysis

Page 56: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

IBM Page Detailer

packet sniffer

Windows only

IE, FF, any .exec:\windows\wd_WS2s.iniExecutable=(NETSCAPE.EXE),(NETSCP6.EXE),

(firefox.exe)

free trial, $300 license

http://alphaworks.ibm.com/tech/pagedetailer

Page 57: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

http://alphaworks.ibm.com/tech/pagedetailer

Page 58: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Firebug

web development evolved

inspect and edit HTML

tweak and visualize CSS

debug and profile JavaScript

monitor network activity (caveat)

Firefox extension

free

http://getfirebug.com/

Page 59: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Takeaways

focus on the frontend

harvest the low-hanging fruit

you do control user response times

small investment up front keeps on giving

LOFNO – be an advocate for your users

Page 60: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

Steve [email protected]

Page 61: High Performance Web Sites 14 rules for faster pages Steve Souders Chief Performance Yahoo! souders@yahoo-inc.com

CC Images Used"Need for Speed" by Amnemon:

http://www.flickr.com/photos/marinacvinhal/379111290/"Max speed 15kmh" by xxxtoff:

http://www.flickr.com/photos/xxxtoff/219781763/"maybe" by Tal Bright:

http://www.flickr.com/photos/bright/118197469/"takeout" by dotpolka:

http://www.flickr.com/photos/dotpolka/249129144/"how do they do that" by Fort Photo:

http://www.flickr.com/photos/fortphoto/388825145/"Absolutely Nothing is Allowed Here" by Vicki & Chuck Rogers:

http://www.flickr.com/photos/two-wrongs/205467442/"Zipper Pocket" by jogales:

http://www.flickr.com/photos/jogales/11519576/"new briefcase" by dcJohn:

http://www.flickr.com/photos/dcjohn/85504455/"Told you it was me!" by Pug!:

http://flickr.com/photos/pugspace/1277023154/"Robert's Legion" by dancharvey:

http://www.flickr.com/photos/dancharvey/2647529/"thank you" by nj dodge: http://flickr.com/photos/nj_dodge/187190601/