blending performance with front-end architecture

145
Blending Performance with Front-End Architecture Chris Griego / boldpx.com Blake Elshire / marbleheadllc.com

Upload: chris-griego

Post on 09-Dec-2014

6.823 views

Category:

Technology


3 download

DESCRIPTION

Presented at Refresh Dallas June 2008 with the following teaser: Think web performance is all about load balancing, database indexes, and memory management? Think again. Recent research shows that 80-90% of the end-user response time is spent on the front-end. The way you develop your site’s HTML, CSS, and JavaScript makes a big impact on how long it takes your site to load. But, speeding up your site doesn’t have to mean throwing out best practices. Chris Griego will show you the guidelines and techniques to combine performance with a solid front-end architecture. Blake Elshire will present a case study for Marblehead’s site, showing the benefits of implementing these changes. Also, a new tool will be demoed that helps automate some of these guidelines.

TRANSCRIPT

Page 1: Blending Performance with Front-End Architecture

Blending Performance with

Front-End Architecture

Chris Griego / boldpx.comBlake Elshire / marbleheadllc.com

Page 2: Blending Performance with Front-End Architecture

Front-End Archiwhat?

Page 3: Blending Performance with Front-End Architecture

A holistic view ofbest practices for

web user interfaces.

Term Coined by Garrett Dimon

Page 4: Blending Performance with Front-End Architecture

CSS

IA

DOM Scripting

Accessibility

Design AJAXMarkup

UserAgents

FlashUsability

Content

Back-EndProjectMgmt.

http://v1.garrettdimon.com/fea/

Page 5: Blending Performance with Front-End Architecture

Why performance?

Page 6: Blending Performance with Front-End Architecture

Speed is a Killer Feature

Page 7: Blending Performance with Front-End Architecture

LOFNOLook out for Number One

Page 8: Blending Performance with Front-End Architecture

Blank Page Your Site

Page 9: Blending Performance with Front-End Architecture

Blank Page Your Site

Content & Features

Page 10: Blending Performance with Front-End Architecture

Blank Page Your Site

Content & Features

Performance

Page 11: Blending Performance with Front-End Architecture

Blank Page Your SiteDo Less

Page 12: Blending Performance with Front-End Architecture

Less is more, but a blank page never made

anyone any money.

Page 13: Blending Performance with Front-End Architecture

Why the front-end?

Page 14: Blending Performance with Front-End Architecture
Page 15: Blending Performance with Front-End Architecture
Page 16: Blending Performance with Front-End Architecture
Page 17: Blending Performance with Front-End Architecture

Empty Cache Primed Cache

aol.com 97% 97%

ebay.com 95% 81%

facebook.com 95% 81%

google.com 47% 0%

search.live.com 67% 0%

msn.com 98% 94%

myspace.com 98% 98%

wikipedia.org 94% 91%

yahoo.com 97% 96%

youtube.com 98% 97%

Time Spent on the Front-End

Page 18: Blending Performance with Front-End Architecture

80-90% of the end user response time is spent

on the front-end.

The Performance Golden Rule

Page 19: Blending Performance with Front-End Architecture

• Greater Potential for Improvement

Page 20: Blending Performance with Front-End Architecture

• Greater Potential for Improvement

• Simpler to Implement

Page 21: Blending Performance with Front-End Architecture

• Greater Potential for Improvement

• Simpler to Implement

• Proven to Work

Page 22: Blending Performance with Front-End Architecture

Why now?

Page 23: Blending Performance with Front-End Architecture
Page 24: Blending Performance with Front-End Architecture
Page 25: Blending Performance with Front-End Architecture
Page 26: Blending Performance with Front-End Architecture
Page 27: Blending Performance with Front-End Architecture

Data-Driven Optimization

Understand Techniques & Their Impact

Page 29: Blending Performance with Front-End Architecture

#2 Use a ContentDelivery Network?

Page 30: Blending Performance with Front-End Architecture

boldpx.com Traffic

Page 31: Blending Performance with Front-End Architecture

Web Server

Page 32: Blending Performance with Front-End Architecture

Amazon S3 as CDN

Page 33: Blending Performance with Front-End Architecture

The goal isn’t to use a CDN. Locate content closer to your users.

Page 34: Blending Performance with Front-End Architecture

Know your Audience

Page 35: Blending Performance with Front-End Architecture

Plan Your Browser Support

Page 36: Blending Performance with Front-End Architecture

How did performance change our

front-end architecture?

Page 37: Blending Performance with Front-End Architecture

HTML

Page 38: Blending Performance with Front-End Architecture

#8 Make JavaScriptand CSS External

Page 39: Blending Performance with Front-End Architecture

Done! But, why?

Page 40: Blending Performance with Front-End Architecture

So they’ll be cached,or are they?

Page 41: Blending Performance with Front-End Architecture

Can hasstyle.css? OK!

Last-Modified: Jan 1

Page 42: Blending Performance with Front-End Architecture

Can hasstyle.css? OK!

Last-Modified: Jan 1

Has style.csschanged

since Jan 1?

No

Page 43: Blending Performance with Front-End Architecture

Can hasstyle.css? OK!

Last-Modified: Jan 1

Has style.csschanged

since Jan 1?No

Has style.csschanged

since Jan 1?

Has style.csschanged

since Jan 1?

Has style.csschanged

since Jan 1?

Has style.csschanged

since Jan 1?

Has style.csschanged

since Jan 1? No No

No

No

No

No

Page 44: Blending Performance with Front-End Architecture

#3 Add an Expires or Cache-Control Header

Page 45: Blending Performance with Front-End Architecture

Expires:

Sun, 17 Jan 2038 19:14:07 GMT

Last 32-bit Unix Timestamp

Page 46: Blending Performance with Front-End Architecture

Can hasstyle.css? OK!

Expires: 2038

Page 47: Blending Performance with Front-End Architecture

Wait! What happens when I update my files?

Page 48: Blending Performance with Front-End Architecture
Page 49: Blending Performance with Front-End Architecture

Can hasstyle.css? OK!

Expires: 2038

Can hasstyle2.css? OK!

Expires: 2038

Page 50: Blending Performance with Front-End Architecture

style.css?1207894558Cache Buster

Page 51: Blending Performance with Front-End Architecture

It doesn’t end there,40-60% of users visit with an empty cache

Page 52: Blending Performance with Front-End Architecture

CSS

Page 53: Blending Performance with Front-End Architecture

#1 Make FewerHTTP Requests

Page 54: Blending Performance with Front-End Architecture

Why?

Page 55: Blending Performance with Front-End Architecture

• Upspeed vs Downspeed

• Cookies

• Referers

• No Content Encoding

Page 56: Blending Performance with Front-End Architecture

“Combine Stylesheets”

Page 57: Blending Performance with Front-End Architecture

Modular Development

Page 58: Blending Performance with Front-End Architecture

• Global Styles

• Home Page

• Search Results

• Individual Products

• Cart & Checkout

• Customer Service

Page 59: Blending Performance with Front-End Architecture

Screen Print JavaScript Handheld

typography.css

colors.css

layout.css

behavior.css

print.css

link link link link

link link link

@ @

doc.write@

link

Page 60: Blending Performance with Front-End Architecture

• global/typography.css

• global/colors.css

• global/layout.css

• global/behavior.css

• global/print.css

• products/typography.css

• products/colors.css

• products/layout.css

• products/behavior/css

• products/print.css

10 Stylesheets? FAIL

Page 61: Blending Performance with Front-End Architecture

We had to aggregate these files together.

Page 62: Blending Performance with Front-End Architecture

Section/Media Based?

• global/screen.css

• global/print.css

• global/handheld.css

• products/screen.css

• products/print.css

• products/handheld.css

Page 63: Blending Performance with Front-End Architecture

Browsers only download the CSSthey need, right?

Page 64: Blending Performance with Front-End Architecture

IE Opera Firefox Safari

screen.css

print.css

handheld.css

projection.css

tv.css

Page 65: Blending Performance with Front-End Architecture

IE Opera Firefox Safari

screen.css

print.css

handheld.css

projection.css

tv.css

!

!

!

!

!

Page 66: Blending Performance with Front-End Architecture

IE Opera Firefox Safari

screen.css

print.css

handheld.css

projection.css

tv.css

! !

! !

! !

! !

! !

Page 67: Blending Performance with Front-End Architecture

IE Opera Firefox Safari

screen.css

print.css

handheld.css

projection.css

tv.css

! ! !

! ! !

! ! !

! ! !

! ! !

Page 68: Blending Performance with Front-End Architecture

IE Opera Firefox Safari

screen.css

print.css

handheld.css

projection.css

tv.css

! ! ! !

! ! ! !

! ! !

! ! !

! ! !

Page 69: Blending Performance with Front-End Architecture

IE Opera FirefoxSafari & iPhone

screen.css

print.css

handheld.css

projection.css

tv.css

! ! ! !

! ! ! !

! ! !

! ! !

! ! !

Page 70: Blending Performance with Front-End Architecture

@media to the rescue

Page 71: Blending Performance with Front-End Architecture

Section Based

• global.css

• products.css

Page 72: Blending Performance with Front-End Architecture

But what aboutour @import?

Page 73: Blending Performance with Front-End Architecture

#27 Choose link over @import

Page 74: Blending Performance with Front-End Architecture

C-Grade Browser Support

Page 75: Blending Performance with Front-End Architecture

But what about behavior.css?

Page 76: Blending Performance with Front-End Architecture

<script type="text/javascript">! if (de = document.documentElement) {! ! de.className += " js";! }</script>

Page 77: Blending Performance with Front-End Architecture

div#expandable {! display: block;}

.js div#expandable {! display: none;}

Page 78: Blending Performance with Front-End Architecture

Don’t forget to aggregate any 3rd-party

stylesheets.

Page 79: Blending Performance with Front-End Architecture

JavaScript

Page 80: Blending Performance with Front-End Architecture

#1 Make FewerHTTP Requests

Page 81: Blending Performance with Front-End Architecture

No media types to worry about :)

Page 82: Blending Performance with Front-End Architecture

3rd-Party Libraries

Page 83: Blending Performance with Front-End Architecture

3rd-Party Analytics

Page 84: Blending Performance with Front-End Architecture

#10 MinifyJavaScript and CSS

Page 85: Blending Performance with Front-End Architecture

Practice Safe Compression

Minification vs Obfuscation

Page 86: Blending Performance with Front-End Architecture

YUI CompressorWinner among tools compared by Zimbra

Page 87: Blending Performance with Front-End Architecture

#6 Put Scriptsat the Bottom

Page 88: Blending Performance with Front-End Architecture

Come again?

Page 89: Blending Performance with Front-End Architecture

Why?

Page 90: Blending Performance with Front-End Architecture

Scripts blockparallel downloads

Page 91: Blending Performance with Front-End Architecture
Page 92: Blending Performance with Front-End Architecture

Images

Page 93: Blending Performance with Front-End Architecture

Maximize Parallel DownloadsUse Multiple Hostnames

Page 94: Blending Performance with Front-End Architecture
Page 95: Blending Performance with Front-End Architecture
Page 96: Blending Performance with Front-End Architecture
Page 97: Blending Performance with Front-End Architecture

#1 Make FewerHTTP Requests

Page 98: Blending Performance with Front-End Architecture

CSS SpritesNot supported in Opera 6

(Not a problem if extended C-grade support)

Page 100: Blending Performance with Front-End Architecture

#30 OptimizeCSS Sprites

Page 101: Blending Performance with Front-End Architecture

Use PNGs

Page 102: Blending Performance with Front-End Architecture

• pngcrush

• optipng

• pngout

Re-compress

Page 103: Blending Performance with Front-End Architecture

File Original pngout optipng pngcrush

optipng +

pngout

pngout +

optipng Best

_global/body-background.png (were GIF, changed image)

_global/html-background.png (were GIF, changed image)

_global/left-background.png (were GIF)

_global/right-background.png (were GIF)

logos/bold-pixel.png

portfolio/banctec-international/home-thumbnail.png

portfolio/banctec-international/home.png

portfolio/banctec-international/industries-thumbnail.png

portfolio/banctec-international/industries.png

portfolio/banctec-international/leadership-thumbnail.png

portfolio/banctec-international/leadership.png

portfolio/banctec-international/worldwide-thumbnail.png

portfolio/banctec-international/worldwide.png

portfolio/destination-beer/age-verification-thumbnail.png

portfolio/destination-beer/age-verification.png

portfolio/destination-beer/home-thumbnail.png

portfolio/destination-beer/home.png

portfolio/destination-beer/single-article-thumbnail.png

portfolio/destination-beer/single-article.png

portfolio/destination-beer/single-beer-thumbnail.png

portfolio/destination-beer/single-beer.png

portfolio/guidewire-connection/home-thumbnail.png

portfolio/guidewire-connection/home.png

portfolio/guidewire-connection/single-thumbnail.png

portfolio/guidewire-connection/single.png

portfolio/guidewire-connection/tag-cloud-thumbnail.png

portfolio/guidewire-connection/tag-cloud.png

portfolio/hotels-com-promotions/deals-landing-thumbnail.png

portfolio/hotels-com-promotions/deals-landing.png

portfolio/hotels-com-promotions/deals-last-minute-thumbnail.png

portfolio/hotels-com-promotions/deals-last-minute.png

portfolio/hotels-com-promotions/deals-search-results-thumbnail.png

portfolio/hotels-com-promotions/deals-search-results.png

portfolio/hotels-com-promotions/destinations-highlights-thumbnail.png

portfolio/hotels-com-promotions/destinations-highlights.png

portfolio/hotels-com-promotions/destinations-landing-thumbnail.png

portfolio/hotels-com-promotions/destinations-landing.png

portfolio/hotels-com-promotions/destinations-things-to-do-thumbnail.png

portfolio/hotels-com-promotions/destinations-things-to-do.png

portfolio/hotels-com-promotions/interests-landing-thumbnail.png

portfolio/hotels-com-promotions/interests-landing.png

portfolio/hotels-com-promotions/interests-style-1-thumbnail.png

portfolio/hotels-com-promotions/interests-style-1.png

portfolio/hotels-com-promotions/interests-style-2-thumbnail.png

portfolio/hotels-com-promotions/interests-style-2.png

portfolio/my-global-career/coming-soon-thumbnail.png

portfolio/my-global-career/coming-soon.png

portfolio/my-global-career/home-thumbnail.png

portfolio/my-global-career/home.png

portfolio/my-global-career/single-thumbnail.png

portfolio/my-global-career/single.png

portfolio/nationpoint/home-thumbnail.png

portfolio/nationpoint/home.png

portfolio/nationpoint/second-level-thumbnail.png

portfolio/nationpoint/second-level.png

portfolio/nationpoint/third-level-thumbnail.png

portfolio/nationpoint/third-level.png

portfolio/nuts-about-southwest/author-thumbnail.png

portfolio/nuts-about-southwest/author.png

portfolio/nuts-about-southwest/home-thumbnail.png

portfolio/nuts-about-southwest/home.png

portfolio/nuts-about-southwest/single-thumbnail.png

portfolio/nuts-about-southwest/single.png

1,095 519 500 514 500 421 591

366 421 489 489 421 420 420

7,941 3,277 3,271 7,941 3,271 3,269 3,269

8,034 3,323 3,318 8,034 3,318 3,317 3,317

11,512 10,458 11,498 11,498 10,458 10,458 10,458

19,300 17,005 19,287 19,287 17,005 17,005 17,005

294,566 262,812 282,131 287,982 262,812 262,812 262,812

11,675 10,518 11,675 11,675 10,518 10,518 10,518

158,477 145,627 150,086 156,674 145,627 145,627 145,627

10,718 10,291 10,718 10,718 10,291 10,291 10,291

193,328 174,903 184,357 184,566 174,903 174,903 174,903

14,675 13,313 14,675 14,675 13,313 13,313 13,313

141,279 130,111 50,869 50,905 50,869 50,459 50,459

14,830 13,628 14,830 14,830 13,628 13,628 13,628

434,725 405,972 324,403 325,084 324,403 323,993 323,993

12,593 11,646 12,592 12,593 11,646 11,646 11,646

427,672 412,464 424,851 425,061 412,464 412,464 412,464

13,972 12,761 13,972 13,972 12,761 12,761 12,761

625,005 586,651 615,369 619,032 586,651 586,651 586,651

10,933 10,248 10,933 10,933 10,248 10,248 10,248

389,286 366,527 385,514 385,510 366,527 366,527 366,527

14,915 14,073 14,915 14,915 14,073 14,073 14,073

569,420 525,387 362,678 363,856 362,678 362,268 362,268

12,931 12,177 12,931 12,931 12,177 12,177 12,177

555,663 508,414 311,421 312,628 311,421 311,011 311,011

18,756 18,046 18,667 18,667 18,046 18,046 18,046

375,744 339,840 247,205 247,792 247,205 246,795 246,795

9,576 8,601 9,576 9,576 8,601 8,601 8,601

156,428 126,284 110,236 110,665 110,236 109,897 109,897

13,725 12,702 13,725 13,725 12,702 12,702 12,702

241,645 199,557 174,411 175,148 174,411 174,072 174,072

14,155 13,040 14,155 14,155 13,040 13,040 13,040

313,733 276,713 296,396 309,666 276,713 276,713 276,713

11,287 10,302 11,287 11,287 10,302 10,302 10,302

177,905 144,523 124,210 124,490 124,210 123,871 123,871

16,006 14,577 16,006 16,006 14,577 14,577 14,577

212,144 179,899 171,445 172,787 171,445 171,106 171,106

10,002 9,081 10,002 10,002 9,081 9,081 9,081

179,272 159,010 137,786 138,240 137,786 137,749 137,749

10,929 10,134 10,919 10,919 10,134 10,134 10,134

265,281 236,632 254,436 261,774 236,632 236,632 236,632

19,507 17,638 19,507 19,507 17,638 17,638 17,638

526,448 469,440 498,074 501,692 469,440 469,440 469,440

17,105 15,924 17,099 17,099 15,924 15,924 15,924

372,867 341,818 363,556 367,763 341,818 341,818 341,818

11,957 10,753 11,935 11,937 10,753 10,753 10,753

210,693 200,477 157,345 157,920 147,704 200,477 147,704

10,426 9,854 10,426 10,426 9,854 9,854 9,854

185,275 158,339 145,358 145,748 145,358 145,019 145,019

12,462 11,931 12,462 12,462 11,931 11,931 11,931

203,328 173,799 158,944 159,331 158,944 158,605 158,605

14,792 13,660 14,792 14,792 13,660 13,660 13,660

214,510 195,392 208,089 214,122 195,392 195,392 195,392

16,506 15,519 16,506 16,506 15,519 15,519 15,519

231,207 203,060 214,695 219,641 203,060 203,060 203,060

14,691 13,650 14,691 14,691 13,650 13,650 13,650

119,610 93,060 81,434 81,610 81,434 81,095 81,095

16,209 15,665 16,209 16,209 15,665 15,665 15,665

521,772 486,164 432,674 450,972 415,364 486,164 415,364

17,386 15,781 17,371 17,371 15,781 15,781 15,781

531,651 490,081 442,842 455,716 423,514 490,081 423,514

17,582 16,080 17,516 17,516 16,080 16,080 16,080

753,014 710,017 672,829 681,660 638,663 710,017 638,663

Total 10,020,497 9,099,569 8,412,099 8,525,893 8,094,250 8,351,201 8,089,877

Page 104: Blending Performance with Front-End Architecture

pngout FTW

Page 105: Blending Performance with Front-End Architecture

pngout + optipng -o7

Page 106: Blending Performance with Front-End Architecture

Mini Q&A

Page 107: Blending Performance with Front-End Architecture

MarbleheadLLC.comCase Study

Page 108: Blending Performance with Front-End Architecture

Simple 1 page web site

Page 109: Blending Performance with Front-End Architecture
Page 110: Blending Performance with Front-End Architecture

Load time was 12 sec.

Page 111: Blending Performance with Front-End Architecture

What were the problems?

Page 112: Blending Performance with Front-End Architecture

#1 Fewer HTTP requests

Page 113: Blending Performance with Front-End Architecture

43 HTTP Requests :(

Page 114: Blending Performance with Front-End Architecture

What caused this?

• 1 HTML file

• 23 Images in CSS

• 8 JavaScript files

• 5 CSS Style Sheets

• 6 Images in HTML

Page 115: Blending Performance with Front-End Architecture

How We Fixed It

• CSS Sprites (23 CSS Images to 5)

• Combined and Minified

• 8 JavaScript files to 2

• 5 CSS files to 1

• Moved a lot of images to HTML 18

Page 116: Blending Performance with Front-End Architecture

Reduced to 27 HTTP Requests

Page 117: Blending Performance with Front-End Architecture

#3 Expires Headers

Page 118: Blending Performance with Front-End Architecture

Nothing was getting cached

Page 119: Blending Performance with Front-End Architecture

~1MB requested on every refresh

Page 120: Blending Performance with Front-End Architecture

• Images, CSS, and JS are cached for 10 years

• HTML is cached for 4 hours

Far Future Expires FTW

Page 121: Blending Performance with Front-End Architecture

Now initial load ~1MBRefresh load 5K.

Page 122: Blending Performance with Front-End Architecture

Next Problem

Page 123: Blending Performance with Front-End Architecture

Needed to reduce file size

Page 124: Blending Performance with Front-End Architecture

#4 Gzip components

Page 125: Blending Performance with Front-End Architecture

Apache handles text files pretty well with mod_deflate & mod_gzip

Page 126: Blending Performance with Front-End Architecture

Images?

Page 127: Blending Performance with Front-End Architecture

Optimized Images with pngout

Page 128: Blending Performance with Front-End Architecture

Major file size reduction

Before: 1095.3K

After: 950K

Page 129: Blending Performance with Front-End Architecture

Making it even faster

Page 130: Blending Performance with Front-End Architecture

Played with multiple asset host names

Page 131: Blending Performance with Front-End Architecture

Browsers can now load more than 2 assets at a time

Page 132: Blending Performance with Front-End Architecture

Saw biggest increase in download time

Page 133: Blending Performance with Front-End Architecture

Overall Performance Increases

• 43 HTTP Requests

• Roughly 1MB file size

• No Caching

• Refresh 43 requests 1MB

• Downloading 2 assets

• Load time: ~12 seconds

Before Changes

• 23 HTTP Requests

• 950K file size

• Caching in place

• Refresh 2 requests ~5K

• Downloading 8 assets

• Load time: ~2 seconds

After Changes

Page 134: Blending Performance with Front-End Architecture

One more thing…

Page 135: Blending Performance with Front-End Architecture

Save & Reload!S !R

Traditional Front-End Workflow

Page 136: Blending Performance with Front-End Architecture

Save, Build & Reload!S !B !R

Traditional Back-End Workflow

Page 137: Blending Performance with Front-End Architecture

Traditional Build Tools?

Page 138: Blending Performance with Front-End Architecture

Blender

Page 139: Blending Performance with Front-End Architecture

Blender is like ant or make for the front-end. It aggregates and

compresses CSS and/or JavaScript assets for a site into efficient, production-ready files.

Page 140: Blending Performance with Front-End Architecture

• Open Source (MIT)

• Command Line Tool (Ruby)

• Uses the YUI Compressor

Page 141: Blending Performance with Front-End Architecture

css/global-min.css: - css/global.cssjs/global-min.js: - js/global.js

Blendfile Format

Page 142: Blending Performance with Front-End Architecture

_behavior: _global-min.js: - ../_vendor/jquery/jquery.js - ../_vendor/shadowbox/src/js/adapter/shadowbox-jquery.js - ../_vendor/shadowbox/src/js/shadowbox.js - _global.js - ../_vendor/google-analytics/ga.js - _analytics.js _analytics-min.js: - ../_vendor/google-analytics/ga.js - _analytics.js_style: _global: ../_global-min.css: - ../../_vendor/shadowbox/src/css/shadowbox.css - typography.css - typography-print.css - colors.css - colors-print.css - layout-screen.css - layout-print.css

Boldpx.com Blendfile

Page 143: Blending Performance with Front-End Architecture

Usage: blend [options]

-h, --help Show this message

-V, --version Prints Blender's version number

-g, --generate Generate a stub Blendfile

-f, --file FILE Use given Blendfile

-t, --type TYPE Select file type to blend (css, js)

-c, --cache-buster [BUSTER] Append cache busters to URLs in CSS, defaults to timestamps

--force Force blending when source files aren't newer than output files

--yui=YUIOPTS Pass arguments to YUI Compressor

-d, --data EXPERIMENTAL Convert url(file.ext) to url(data:) in CSS files

-z, --gzip EXPERIMENTAL Also create gzip output files

Command Line Options

Page 144: Blending Performance with Front-End Architecture

Seeking Testersand Contributors

Page 145: Blending Performance with Front-End Architecture

Q&A