improving front end performance

70
Friday, May 4, 2012

Upload: joseph-scott

Post on 13-May-2015

4.137 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Improving Front End Performance

Friday, May 4, 2012

Page 2: Improving Front End Performance

This Slide Is Blank

Friday, May 4, 2012

Page 3: Improving Front End Performance

Friday, May 4, 2012

Page 5: Improving Front End Performance

ImprovingFront-EndPerformance

Friday, May 4, 2012

Page 6: Improving Front End Performance

Improve the Perceived Responsiveness of a Site

Friday, May 4, 2012

Page 7: Improving Front End Performance

The Measurements

Friday, May 4, 2012

Page 8: Improving Front End Performance

Chrome Network Panel

Friday, May 4, 2012

Page 9: Improving Front End Performance

Chrome Page Speed

Friday, May 4, 2012

Page 10: Improving Front End Performance

webpagetest.org

http://www.webpagetest.org/result/120501_S5_45YNJ/

Friday, May 4, 2012

Page 11: Improving Front End Performance

The Techniques

Friday, May 4, 2012

Page 12: Improving Front End Performance

HTTP Compression

Friday, May 4, 2012

Page 13: Improving Front End Performance

HTTP Compression

Request: Accept-Encoding: deflate, gzip

Response: Content-Encoding: gzip

Friday, May 4, 2012

Page 14: Improving Front End Performance

HTTP Compression

HTTP/1.1 200 OKExpires: Sun, 26 Dec 2032 06:12:01 GMTVary: Accept-EncodingContent-Encoding: gzipLast-Modified: Wed, 25 Apr 2012 15:27:45 GMTETag: "2942247273"Content-Type: text/cssAccept-Ranges: bytesContent-Length: 43524Date: Fri, 27 Apr 2012 02:09:28 GMTServer: lighttpd-yt/1.4.18Age: 227872Cache-Control: public, max-age=31104000

youtube.com CSS Request

Friday, May 4, 2012

Page 15: Improving Front End Performance

HTTP Compression

Response: Vary: Accept-Encoding

Friday, May 4, 2012

Page 16: Improving Front End Performance

HTTP Keep Alive

Friday, May 4, 2012

Page 17: Improving Front End Performance

HTTP Keep Alive

Request: Connection: keep-alive

Response: Connection: keep-alive

Friday, May 4, 2012

Page 18: Improving Front End Performance

HTTP Caching

Friday, May 4, 2012

Page 19: Improving Front End Performance

HTTP Caching

Response:

Expires: Fri, 05 May 2017 01:06:01 GMT

Friday, May 4, 2012

Page 20: Improving Front End Performance

HTTP Caching

Response:

Cache-Control: max-age: 31536000

Friday, May 4, 2012

Page 21: Improving Front End Performance

HTTP Caching

Response: Last-Modified: Tue, 12 Dec 2006 03:03:59 GMT

Request:If-Modified-Since: Tue, 12 Dec 2006 03:03:59 GMT

Friday, May 4, 2012

Page 22: Improving Front End Performance

HTTP Caching

Response: Etag: "850d9-d2ff-4b881f248ec80"

Request: If-None-Match: "850d9-d2ff-4b881f248ec80"

Friday, May 4, 2012

Page 23: Improving Front End Performance

HTTP Caching

Response: HTTP/1.1 200 OK

HTTP/1.1 304 Not Modified

Friday, May 4, 2012

Page 24: Improving Front End Performance

HTTP Caching

Etag, so misunderstood

Friday, May 4, 2012

Page 25: Improving Front End Performance

HTTP Caching

Updating Cached Resources

Friday, May 4, 2012

Page 26: Improving Front End Performance

HTTP Caching

http://example.com/css/style.css?v=1

http://example.com/css/style.1.css

Friday, May 4, 2012

Page 27: Improving Front End Performance

Avoid Redirects

Friday, May 4, 2012

Page 28: Improving Front End Performance

Avoid Redirects

utah.gov

Friday, May 4, 2012

Page 29: Improving Front End Performance

Avoid Redirects

utah.gov

utah.gov/index.html

Friday, May 4, 2012

Page 30: Improving Front End Performance

Avoid Redirects

utah.gov

utah.gov/index.html

120ms

Friday, May 4, 2012

Page 31: Improving Front End Performance

Avoid Redirects

deseretnews.com

Friday, May 4, 2012

Page 32: Improving Front End Performance

Avoid Redirects

deseretnews.com

www.deseretnews.com/

Friday, May 4, 2012

Page 35: Improving Front End Performance

CSS

Friday, May 4, 2012

Page 36: Improving Front End Performance

CSS

Always at the top!

Friday, May 4, 2012

Page 37: Improving Front End Performance

CSS

#IDs are only slightly faster than .CLASSes

Friday, May 4, 2012

Page 38: Improving Front End Performance

CSS

#nav a

Browsers read right to left

Friday, May 4, 2012

Page 39: Improving Front End Performance

CSS

Bad: #nav * { }

Better: #nav a { }

Betterest: #nav .now { }

Friday, May 4, 2012

Page 40: Improving Front End Performance

CSS

html body .wrapper #content a{}

VS.

#content a{}

Friday, May 4, 2012

Page 42: Improving Front End Performance

CSS

Minify your CSS files

Friday, May 4, 2012

Page 43: Improving Front End Performance

CSS

Use CSS Sprites

http://spriteme.org/

Friday, May 4, 2012

Page 44: Improving Front End Performance

Javascript

Friday, May 4, 2012

Page 45: Improving Front End Performance

Javascript

Always at the bottom!

Friday, May 4, 2012

Page 46: Improving Front End Performance

JavascriptBottom and Async!

Friday, May 4, 2012

Page 47: Improving Front End Performance

JavascriptBottom and Async!

(function() { var js = document.createElement( 'script' ); js.async = true; js.src = '/js/awesome.js’;

var s = document.getElementsByTagName( 'script' )[0]; s.parentNode.insertBefore( js, s );} )();

Friday, May 4, 2012

Page 48: Improving Front End Performance

JavascriptBottom and Async!

(function() { var js = document.createElement( 'script' ); js.async = true; js.src = '/js/awesome.js’;

var s = document.getElementsByTagName( 'script' )[0]; s.parentNode.insertBefore( js, s );} )();

Friday, May 4, 2012

Page 49: Improving Front End Performance

JavascriptBottom and Async!

(function() { var js = document.createElement( 'script' ); js.async = true; js.src = '/js/awesome.js’;

var s = document.getElementsByTagName( 'script' )[0]; s.parentNode.insertBefore( js, s );} )();

Friday, May 4, 2012

Page 50: Improving Front End Performance

JavascriptBottom and Async!

(function() { var js = document.createElement( 'script' ); js.async = true; js.src = '/js/awesome.js’;

var s = document.getElementsByTagName( 'script' )[0]; s.parentNode.insertBefore( js, s );} )();

Friday, May 4, 2012

Page 51: Improving Front End Performance

Javascript

jQuerySelector Performance

Friday, May 4, 2012

Page 52: Improving Front End Performance

Javascript

<div id="box"> <p> Hi </p></div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><script> var box = $('#box');</script>

Friday, May 4, 2012

Page 53: Improving Front End Performance

Javascript

$('#box > p');

$('#box p');

$('#box').children('p');

$('p', $('#box'));

$('p', '#box');

Friday, May 4, 2012

Page 54: Improving Front End Performance

Javascript

$('#box > p'); /* Horrible! */

$('#box p'); /* Horrible! */

$('#box').children('p'); /* Bad */

$('p', $('#box')); /* Less Bad */

$('p', '#box'); /* Less Bad */

Friday, May 4, 2012

Page 55: Improving Front End Performance

Javascript

$('#box').find('p');

$('p', box);

box.find('p');

Friday, May 4, 2012

Page 56: Improving Front End Performance

Javascript

$('#box').find('p'); /* Better */

$('p', box); /* Almost there! */

box.find('p'); /* Best! */

http://jsperf.com/jquery-selector-perf-right-to-left/57

Friday, May 4, 2012

Page 57: Improving Front End Performance

Javascript

document.getElementById("box").getElementsByTagName("p");

box.find('p');

Friday, May 4, 2012

Page 58: Improving Front End Performance

Javascript

document.getElementById("box").getElementsByTagName("p");/* 2,000k ops/sec */

box.find('p'); /* 48k ops/sec */

http://jsperf.com/jquery-selector-perf-right-to-left/91

Friday, May 4, 2012

Page 59: Improving Front End Performance

Javascript

Be careful withevent handlers

Friday, May 4, 2012

Page 60: Improving Front End Performance

Javascript

Carefully minimizeyour Javascript

Friday, May 4, 2012

Page 61: Improving Front End Performance

Various Tips

Friday, May 4, 2012

Page 62: Improving Front End Performance

Separate DomainFor Static Resources

example.com

fakecdn.example.com

fakecdnexample.com

Friday, May 4, 2012

Page 63: Improving Front End Performance

Optimize Images

pngcrush

jpegtran

http://www.smushit.com/ysmush.it/

http://imageoptim.com/

Friday, May 4, 2012

Page 64: Improving Front End Performance

Delay Loading Resources

<img data-gravatar_hash="713072bbe89035a79c17d19e53dd5d9b" class="load-gravatar" height="64" width="64" src="https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=64&d=mm" />

https://github.com/josephscott/async-gravatars

Friday, May 4, 2012

Page 65: Improving Front End Performance

Have a favicon.ico

Small

Cacheable

Friday, May 4, 2012

Page 66: Improving Front End Performance

Cacheable AJAX

Standard Rules Apply

Friday, May 4, 2012

Page 67: Improving Front End Performance

Experiment with cuzillion

http://stevesouders.com/cuzillion/

Friday, May 4, 2012

Page 68: Improving Front End Performance

Experiment with Browserscope

http://www.browserscope.org/

Friday, May 4, 2012