0% found this document useful (0 votes)
149 views97 pages

14 Rules for Faster Web Performance

The document summarizes research on improving web page performance through front-end optimizations. It discusses how the majority of page load time is spent downloading components from the front-end. The key findings include that 40-60% of users view pages with empty caches, requiring downloading all components, and 20% of page views also have empty caches. It emphasizes the importance of techniques like minimizing HTTP requests, leveraging caching, compressing content, and parallelizing downloads to optimize performance for both empty and full cache scenarios.

Uploaded by

Yogendra Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views97 pages

14 Rules for Faster Web Performance

The document summarizes research on improving web page performance through front-end optimizations. It discusses how the majority of page load time is spent downloading components from the front-end. The key findings include that 40-60% of users view pages with empty caches, requiring downloading all components, and 20% of page views also have empty caches. It emphasizes the importance of techniques like minimizing HTTP requests, leveraging caching, compressing content, and parallelizing downloads to optimize performance for both empty and full cache scenarios.

Uploaded by

Yogendra Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

High Performance Web Sites

14 rules for faster-loading pages

Steve Souders

Tenni Theurer

souders@[Link]

tenni@[Link]

Introduction

Exceptional Performance
started in 2004
quantify and improve the performance of
all Yahoo! products worldwide
center of expertise
build tools, analyze data

gather, research, and evangelize best


practices

Scope
performance breaks into two categories
response time
efficiency

current focus is response time


of web products

Rough Cuts: now


Hardcopy: Summer 2007

[Link]

The Importance of Front-End


Performance

Back-end vs. Front-end


Empty Cache

Full Cache

[Link]

82%

86%

[Link]

94%

86%

[Link]

81%

92%

[Link]

98%

92%

[Link]

86%

64%

[Link]

97%

95%

[Link]

96%

86%

[Link]

80%

88%

[Link]

95%

88%

[Link]

97%

95%

percentage of time spent on the front-end

The Performance Golden Rule


80-90% of the end-user response time is
spent on the front-end. Start there.
Greater potential for improvement
Simpler

Proven to work

Schedule
Performance Research
break

14 Rules
break
Case Studies
Live Analysis

Performance
Research

perceived response time

performance
speed
slow crawl boring
snail

enjoyable
urgent instant
stagnant unexceptional
accelerate
perception snap
yawn unresponsive
achievement
better
improve
impatient delay
moderate
action
pace
quick
blahpleasant
subdue drag
apathetic
promote
swift
prolong
slack
loadcool
sluggish

late

maximum
prompt
sleepy drive unexciting

reduced
lag complex
heavy
advance fast
hurry rush
unmemorable
obscure
satisfying
feel exceptional
why wait
brisk rapid
exciting

what is the end users experience?

User Perception
Usability and perception are important for
performance.
The users perception is more relevant than
actual unload-to-onload response time.
Definition of "user onload" is undefined or
varies from one web page to the next.

[Link]

80/20 Performance Rule


Vilfredo Pareto:
80% of consequences come from 20% of causes

Focus on the 20% that affects 80% of the


end-user response time.
Start at the front-end.

Empty vs. Full Cache

user requests
[Link]

user requests
other web pages

user re-requests
[Link]

Empty vs. Full Cache

1
user requests
[Link]

with an empty cache

user requests
other web pages

user re-requests
[Link]

dns lookup
html
image
image
dns lookup
script
image
image
image
image
image
image
image
image
script
image
image
image
image
image
image
image
image
script
dns lookup
image
image
image
image
image
dns lookup
script
script
stylesheet
image

0.5

1.5

2.5

Empty vs. Full Cache

user requests
[Link]

user requests
other web pages

user re-requests
[Link]

Empty vs. Full Cache

user requests
[Link]

user requests
other web pages

user re-requests
[Link]

html
image
image
0

0.5

1.5

2.5

Expires header
with a full cache

Empty vs. Full Cache


empty cache
2.4 seconds
full cache
0.9 seconds
83% fewer bytes
90% fewer HTTP requests

How much does this benefit our users?


It depends on how many users have
components in cache.
What percentage of users view a page with
an empty cache*?
*

Empty cache means the browser has to request the components


instead of pulling them from the browser disk cache.

What percentage of page views are done


with an empty cache*?

[Link]

Browser Cache Experiment


Add a new image to your page
<img src="image/[Link]" height="1" width="1"/>

}1 px
with the following response headers:
Expires: Thu, 15 Apr 2004 [Link] GMT
Last-Modified: Wed, 28 Sep 2006 [Link] GMT

Browser Cache Experiment


Requests from the browser will have
one of these response status codes:
200 The browser does not have the image
in its cache.
304 The browser has the image in its cache,
but needs to verify the last modified date.

Browser Cache Experiment


What percentage of users
view with an empty cache?

What percentage of page


views are done with an
empty cache?

# unique users with at least


one 200 response
total # unique users

total # of 200 responses


# of 200 + # of 304
responses

}1 px

Surprising Results
users with
empty cache

page views with


empty cache

100.0%
90.0%

unique users with empty cache

40-60%

80.0%

page views with empty cache

percentage

70.0%
60.0%
50.0%
40.0%
30.0%
20.0%
10.0%
0.0%
0

10 11 12 13 14 15 16 17 18 19 20

day of experiment

~20%

Experiment Takeaways
Keep in mind the empty cache user
experience. It might be more prevalent
than you think!
Use different techniques to optimize full
versus empty cache experience.

[Link]

HTTP Quick Review

1
user requests
[Link]

HTTP response header sent by the web server:


HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Set-Cookie: C=abcdefghijklmnopqrstuvwxyz; domain=.[Link]

HTTP Quick Review

user requests
[Link]

user requests
[Link]

HTTP request header sent by the browser:


GET / HTTP/1.1
Host: [Link]
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;
Cookie: C=abcdefghijklmnopqrstuvwxyz;

HTTP Quick Review

user requests
[Link]

user requests
[Link]

HTTP request header sent by the browser:


GET / HTTP/1.1
Host: [Link]
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;
Cookie: C=abcdefghijklmnopqrstuvwxyz;

HTTP Quick Review

user requests
[Link]

user requests
[Link]

HTTP request header sent by the browser:


GET / HTTP/1.1
Host: [Link]
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;
Cookie: C=abcdefghijklmnopqrstuvwxyz;

HTTP Quick Review

user requests
[Link]

user requests
[Link]

HTTP request header sent by the browser:


GET / HTTP/1.1
Host: [Link]
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;
Cookie: C=abcdefghijklmnopqrstuvwxyz;

Impact of Cookies on Response Time


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

80 ms delay

dialup users

.[Link] cookie sizes


100%

1.55%

percentage of page views

17.79%

over 1501 bytes


1001-1500 bytes
51.80%

501-1000 bytes
1-500 bytes

28.86%

0%

Analysis of Cookie Sizes across the Web


Total Cookie Size
Amazon

60 bytes

Google

72 bytes

Yahoo

122 bytes

CNN

184 bytes

YouTube

218 bytes

MSN

268 bytes

eBay

331 bytes

MySpace

500 bytes

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

[Link]

Parallel Downloads
Two components

in parallel

per hostname

GIF
GIF

GIF

GIF

GIF

GIF

HTTP/1.1

Parallel Downloads
Two in parallel
Four in parallel

Eight in parallel

html
component
component
component
component
component
component
component
component
component
component
0

0.2

0.4

0.6

0.8

1.2

1.4

0.2

0.4

0.6

0.8

1.2

1.4

0.2

0.4

0.6

0.8

1.2

1.4

html
component
component
component
component
component
component
component
component
component
component

html
component
component
component
component
component
component
component
component
component
component

Maximizing Parallel Downloads

response time
(seconds)

aliases

Maximizing Parallel Downloads


1.40

36 x 36 px (0.9 Kb)

116 x 61 px (3.4 Kb)

1.20

1.00

0.80

response time
(seconds)

0.60

0.40

0.20

0.00
1

aliases

10

Maximizing Parallel Downloads


1.40

average

36 x 36 px (0.9 Kb)

116 x 61 px (3.4 Kb)

1.20

1.00

0.80

response time
(seconds)

0.60

0.40

0.20

0.00
1

aliases

10

Maximizing Parallel Downloads


1.40

average

36 x 36 px (0.9 Kb)

116 x 61 px (3.4 Kb)

1.20

1.00

0.80

response time
(seconds)

0.60

0.40

0.20

0.00
1

10

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

Experiment Takeaways
consider the effects of CPU thrashing
DNS lookup times vary across ISPs and
geographic locations
domain names may not be cached

Summary
What the 80/20 Rule Tells Us about
Reducing HTTP Requests
[Link]

Browser Cache Usage Exposed!


[Link]

When the Cookie Crumbles


[Link]

Maximizing Parallel Downloads in the


Carpool Lane
[Link]

14 Rules

14 Rules
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

Make fewer HTTP requests


Use a CDN
Add an Expires header
Gzip components
Put CSS at the top
Move JS to the bottom
Avoid CSS expressions
Make JS and CSS external
Reduce DNS lookups
Minify JS
Avoid redirects
Remove duplicate scripts
Turn off ETags
Make AJAX cacheable and small

Rule 1: Make fewer HTTP requests


image maps
CSS sprites

inline images
combined scripts, combined stylesheets

Image maps
server-side
<a href="[Link]"><img ismap src="[Link]"></a>
[Link]

client-side preferred
<img usemap="#map1" border=0 src="/images/[Link]">
<map name="map1">
<area shape="rect" coords="0,0,31,31" href="[Link]" title="Home">

</map>

drawbacks:
must be contiguous
defining area coordinates tedious, errors
[Link]

CSS Sprites Preferred

<span style="
background-image: url('[Link]');
background-position: -260px -90px;">
</span>

size of combined image is less


not supported in Opera 6
[Link]

Inline Images
data: URL scheme
data:[<mediatype>][;base64],<data>
<IMG ALT=Red Star
SRC="data:image/gif;base64,R0lGODlhDAAMALMLAPN8ffBiYvWWlvrKy/FvcPewsO9VVf
ajo+w6O/zl5estLv/8/AAAAAAAAAAAAAAAACH5BAEAAAsALAAAAAAMAAwAAAQzcElZyryT
EHyTUgknHd9xGV+qKsYirKkwDYiKDBiatt2H1KBLQRFIJAIKywRgmhwAIlEEADs=">

not supported in IE
avoid increasing size of HTML pages:
put inline images in cached stylesheets

[Link]

Combined Scripts,
Combined Stylesheets
Scripts

Stylesheets

[Link]

18

[Link]

11

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

6.5

1.5

[Link]

Average

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

Rule 2: Use a CDN


[Link]

Akamai

[Link]

Akamai

[Link]
[Link]

Akamai, Mirror Image

[Link]
[Link]
[Link]

SAVVIS
Akamai, Limelight

[Link]
[Link]

Akamai

[Link]

distribute your static content before


distributing your dynamic content

Rule 3: Add an Expires header


not just for images
Images Stylesheets
[Link]

Scripts

% Median Age

0/62

0/1

0/3

0%

114 days

[Link]

23/43

1/1

6/18

48%

217 days

[Link]

0/138

0/2

2/11

1%

227 days

[Link]

16/20

0/2

0/7

55%

140 days

1/23

0/1

0/1

4%

454 days

32/35

1/1

3/9

80%

34 days

[Link]

0/18

0/2

0/2

0%

1 day

[Link]

6/8

1/1

2/3

75%

1 day

23/23

1/1

4/4

100%

n/a

0/32

0/3

0/7

0%

26 days

[Link]
[Link]

[Link]
[Link]

Rule 4: Gzip components


you can affect users' download times
90%+ of browsers support compression

Gzip vs. Deflate


Gzip

Deflate

Size

Size Savings

Size Savings

Script

3.3K

1.1K

67%

1.1K

66%

Script

39.7K

14.5K

64%

16.6K

58%

Stylesheet

1.0K

0.4K

56%

0.5K

52%

Stylesheet

14.1K

3.7K

73%

4.7K

67%

Gzip compresses more


Gzip supported in more browsers

Gzip: not just for HTML


HTML
[Link]

[Link]

Scripts

Stylesheets

some

some

[Link]
[Link]

[Link]

[Link]

deflate

deflate

[Link]

[Link]

[Link]

[Link]

some

some

gzip scripts, stylesheets, XML, JSON (not


images, PDF)

Gzip Configuration
Apache 2.x: mod_deflate
AddOutputFilterByType DEFLATE text/html text/css
application/x-javascript

HTTP request
Accept-Encoding: gzip, deflate

HTTP response
Content-Encoding: gzip
Vary: Accept-Encoding

needed for proxies

Gzip Edge Cases


<1% of browsers have problems with gzip
IE 5.5:
[Link]

IE 6.0:
[Link]

Netscape 3.x, 4.x


[Link]

consider adding Cache-Control: Private


remove ETags (Rule 13)
hard to diagnose; problem getting smaller

Rule 5: Put CSS at the top


stylesheets block rendering in IE
[Link]

solution: put stylesheets in HEAD (per spec)

avoids Flash of Unstyled Content


use LINK (not @import)

Slowest is Fastest

Rule 6: Move scripts to the bottom


scripts block parallel downloads across all
hostnames
scripts block rendering of everything below
them in the page
IE and FF
[Link]

Rule 6: Move scripts to the bottom


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

solution: move them as low in the page as


possible

Rule 7: Avoid CSS expressions


used to set CSS properties dynamically in IE
width: expression(
[Link] < 600 ?
600px : auto );

problem: expressions execute many times


mouse move, key press, resize, scroll, etc.

[Link]

One-Time Expressions
expression overwrites itself
<style>
P {
background-color: expression(altBgcolor(this));
}
</style>
<script>
function altBgcolor(elem) {
[Link] = (new
Date()).getHours()%2 ? "#F08A00" : "#B8D4FF";
}
</script>

Event Handlers
tie behavior to (fewer) specific events
[Link] = setMinWidth;
function setMinWidth() {
var aElements =
[Link]("p");
for ( var i = 0; i < [Link]; i++ ) {
aElements[i].[Link] = (
[Link]<600 ?
"600px" : "auto" );
}
}

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. full cache stats
component re-use

external is typically better


home pages may be an exception

Post-Onload Download
inline in front page
download external files after onload
[Link] = downloadComponents;
function downloadComponents() {
var elem = [Link]("script");
[Link] = "[Link]
[Link](elem);
...
}

speeds up secondary pages

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

Rule 9: Reduce DNS lookups


typically 20-120 ms
block parallel downloads

OS and browser both have DNS caches

TTL (Time To Live)


[Link]

1 minute

[Link]

1 minute

[Link]

10 minutes

[Link]

1 hour

[Link]

5 minutes

[Link]

5 minutes

[Link]

1 hour

[Link]

1 hour

[Link]

[Link]

1 minute

5 minutes

TTL how long record can be cached

browser settings override TTL

Browser DNS Cache


IE
DnsCacheTimeout: 30 minutes
KeepAliveTimeout: 1 minute
ServerInfoTimeout: 2 minutes

Firefox

[Link]: 1 minute
[Link]: 20
[Link]: 5 minutes
Fasterfox: 1 hour, 512 entries, 30 seconds

Reducing DNS Lookups


fewer hostnames 2-4
keep-alive

Rule 10: Minify JavaScript


Minify
External?

Minify
Inline?

[Link]

no

no

[Link]

no

no

[Link]

no

no

[Link]

yes

no

[Link]

yes

yes

[Link]

yes

yes

[Link]

no

no

[Link]

no

no

[Link]

yes

yes

[Link]

no

no

minify inline scripts, too

Minify vs. Obfuscate


Original

JSMin Savings

Dojo Savings

204K

31K (15%)

48K (24%)

[Link]

44K

4K (10%)

4K (10%)

[Link]

98K

19K (20%)

24K (25%)

[Link]

88K

23K (27%)

24K (28%)

[Link]

42K

14K (34%)

16K (38%)

[Link]

34K

8K (22%)

10K (29%)

85K

17K (21%)

21K (25%)

[Link]

Average

minify it's safer


[Link]
[Link]

Rule 11: Avoid redirects


3xx status codes mostly 301 and 302
HTTP/1.1 301 Moved Permanently
Location: [Link]

add Expires headers to cache redirects


worst form of blocking

[Link]

Redirects
Redirects

[Link]

no

[Link]

yes secondary page

[Link]

yes initial page

[Link]

yes secondary page

[Link]
[Link]

no
yes initial page

[Link]

yes secondary page

[Link]

yes secondary page

[Link]

yes secondary page

[Link]

no

Avoid Redirects
missing trailing slash
[Link]

use Alias or DirectorySlash

mod_rewrite
CNAMEs
log referer track internal links
outbound links harder
beacons beware of race condition
XHR bail at readyState 2

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

Script Insertion Functions


<?php
function insertScript($jsfile) {
if ( alreadyInserted($jsfile) ) { return; }
pushInserted($jsfile);

if ( hasDependencies($jsfile) ) {
$dependencies = getDependencies($jsfile);
for ( $i = 0; $i < count($dependencies); $i++ ) {
insertScript($dependencies[$i]);
}
}
echo '<script type="text/javascript" src="' .
getVersion($jsfile) . '"></script>";

}
?>

Rule 13: Turn off ETags


unique identifier returned in response
ETag: "c8897e-aee-4165acf0"
Last-Modified: Thu, 07 Oct 2004 [Link] GMT

used in conditional GET requests


If-None-Match: "c8897e-aee-4165acf0"
If-Modified-Since: Thu, 07 Oct 2004 [Link] GMT

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

The Problem with ETags


ETag for a single entity is always different
across servers
ETag format

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

Sites with >1 server return too few 304s


(n-1)/n

Remove them

Apache: FileETag none


IIS: [Link]

Rule 14: Make AJAX cacheable


and small
XHR, JSON, iframe, dynamic scripts can
still be cached, minified, and gzipped
a personalized response should still be
cacheable by that person

AJAX Example: Yahoo! Mail Beta


address book XML request
GET /yab/[...]&r=0.5289571053069156 HTTP/1.1
Host: [Link]
HTTP/1.1 200 OK
Date: Thu, 12 Apr 2007 [Link] GMT
Cache-Control: private,max-age=0
Last-Modified: Sat, 31 Mar 2007 [Link] GMT
Content-Type: text/xml; charset=utf-8
Content-Encoding: gzip

address book changes infrequently


cache it; add last-modified-time in URL

Live Analysis

IBM Page Detailer


packet sniffer
Windows only

IE, FF, any .exe


c:\windows\wd_WS2s.ini
Executable=([Link]),([Link]),([Link])

free trial, $300 license

[Link]

[Link]

Fasterfox
measures load time of pages
alters config settings for faster loading

Firefox extension
free

[Link]

LiveHTTPHeaders
view HTTP headers
Firefox extension

free

[Link]

Firebug
web development evolved
inspect and edit HTML

tweak and visualize CSS


debug and profile JavaScript
monitor network activity (caveat)
Firefox extension
free
[Link]

[Link]

YSlow
performance lint tool
grades web pages for each rule

Firefox extension
Yahoo! internal tool

Conclusion

Takeaways
focus on the front-end
harvest the low-hanging fruit

you do control user response times


LOFNO be an advocate for your users

Links
book: [Link]
examples: [Link]
image maps: [Link]
CSS sprites: [Link]
inline images: [Link]
jsmin: [Link]
dojo compressor: [Link]
HTTP status codes: [Link]
IBM Page Detailer: [Link]
Fasterfox: [Link]
LiveHTTPHeaders: [Link]
Firebug: [Link]
YUIBlog: [Link]
[Link]
[Link]
[Link]
YDN: [Link]
[Link]

You might also like