34
BEING A TWEAKER - MODERN WEB PERFORMANCE TECHNIQUES Chris Love Tellago Inc. http://ProfessionalASPNET.com http://Twitter.com/ChrisLove

Being a tweaker modern web performance techniques

Embed Size (px)

Citation preview

Page 1: Being a tweaker   modern web performance techniques

BEING A TWEAKER - MODERN WEB PERFORMANCE TECHNIQUES

Chris LoveTellago Inc.http://ProfessionalASPNET.comhttp://Twitter.com/ChrisLove

Page 2: Being a tweaker   modern web performance techniques

Diamond SponsorCTREC Hilton

http://www.ctrechilton.com/

Page 3: Being a tweaker   modern web performance techniques

TELLAGO

Page 4: Being a tweaker   modern web performance techniques

REFERENCESEssential Knowledge for Front-End Engineers

Steve Soudershttp://www.stevesouders.com/

http://amzn.to/gwf9pGhttp://amzn.to/gudayQ

http://developer.yahoo.com/performance/rules.html

Page 5: Being a tweaker   modern web performance techniques

SPEED KILLS Customers/Users Are Impatient Speed SEO Factor Amazon: 1 Click Purchase

Case Study Wal-Mart

Page 6: Being a tweaker   modern web performance techniques

SPEED KILLS

http://bit.ly/xfvPMC

Page 7: Being a tweaker   modern web performance techniques

SPEED KILLS

http://bit.ly/xfvPMC

Page 8: Being a tweaker   modern web performance techniques

SPEED KILLS For every 1 second of improvement

they experienced up to a 2% increase in conversions

For every 100 ms of improvement, they grew incremental revenue by up to 1%

SEO benefits for entry pages and reduce bounces

Page 9: Being a tweaker   modern web performance techniques

TOOLS IE – F12

Networking Profiling

FireFox FireBug – Yslow Plugin

WebKit Developer Tools Ctrl + Shift + I

Page 10: Being a tweaker   modern web performance techniques

MAKE FEWER REQUESTS• Each Request Adds More Overhead• Avoid Slicing Images that are not

Reused• Image Maps• CSS Sprites• Inline Images• Combine Scripts and CSS

Page 11: Being a tweaker   modern web performance techniques

BUNDLING & MINIFICATION Reduces Requests Reduces Size

JSMin http://bit.ly/tzBeo YUI Compressor http://yhoo.it/AWec Google Closure Compiler http://bit.ly/aNwjz AJAXMin http://bit.ly/cCCKEI Cassette http://bit.ly/zsGm8X

Page 12: Being a tweaker   modern web performance techniques

BUNDLING & MINIFICATION ASP.NET 4.0 Includes New Tool Gu’s Blog Post http://bit.ly/su4zHd

JS & CSS Granular Control Custom Rules Demo http://bit.ly/q5sFNK

Page 13: Being a tweaker   modern web performance techniques

COMPRESS• Reduces Content being sent over the

wire• Gzip, Deflate• Increases Processer Demand on both

ends• IIS 6 and IIS 7• http://technet2.microsoft.com/windowsserver2008/en/l

ibrary/60f3fa55-f005-496e-9d2f-cc4fc2732fce1033.mspx?mfr=true

• Blowry• Various ISAPI Filters

Page 14: Being a tweaker   modern web performance techniques

IMAGE SPRITES Add Multiple Images

together Great for Icons Use CSS positioning to

set background-image

Page 15: Being a tweaker   modern web performance techniques

IMAGE SPRITES div {

background:url(icon-sprites.png);margin:3px;

} .sprite1 {

width:24px;height:26px;background-position: 0px 0px;

}

Page 16: Being a tweaker   modern web performance techniques

DATA URIS Base64 Encode Data Eliminates Requests Do Not Use for LARGE Images

<img src="data:image/png;base64, {mystery meat} " alt="Texas Rangers">

Page 17: Being a tweaker   modern web performance techniques

SINGLE PAGE APPS Can Reduce Requests Snappy Page & Content Transitions Be Cautious of Browser Memory

Pressures

Page 18: Being a tweaker   modern web performance techniques

DEFERRED CONTENT Load Content in the background Predictive Loading Use the IMG load event to load next

image

Page 19: Being a tweaker   modern web performance techniques

USE CDN Common Scripts & Resources Reduces Requests (sort of) Typically Not Compressed (but that’s

OK)

Page 20: Being a tweaker   modern web performance techniques

USE CDN<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script> window.jQuery || document.write("<script src='@Url.Content("~/js/libs/jquery-1.7.1.min.js")'>\x3C/script>")</script><script src="//ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script><script>window.jQuery.fn.tmpl || document.write("<script src='@Url.Content("~/js/libs/jquery.tmpl.min.js")'>\x3C/script>")</script>

Page 21: Being a tweaker   modern web performance techniques

STYLES @ TOP Browser needs Styles to Render

Markup Avoid Inline Styles

Page 22: Being a tweaker   modern web performance techniques

SCRIPTS @ BOTTOM SCRIPT tag is a blocking Tag Scripts Must Be Evaluated before

proceding Allows markup to be rendered 1st

(perceived perf) Exception - modernizr

Page 23: Being a tweaker   modern web performance techniques

STORAGE LocalStorage IndexDB WebSQL (deprecated)

IndexDB & WebSQL have better perf and reliability

Page 24: Being a tweaker   modern web performance techniques

JQUERY PERFORMANCE Always Use Latest Version Use CDNs (Google, Microsoft)

Page 25: Being a tweaker   modern web performance techniques

USE FOR NOT $.EACHvar array = new Array (); for (var i=0; i<10000; i++) {

array[i] = 0; } console.time('native'); var l = array.length; for (var i=0;i<l; i++) {

array[i] = i; } console.timeEnd('native'); console.time('jquery'); $.each (array, function (i) {

array[i] = i; }); console.timeEnd('jquery');

Page 26: Being a tweaker   modern web performance techniques

USE FOR NOT $.EACH

Page 27: Being a tweaker   modern web performance techniques

USE IDS NOT CLASSESconsole.time('class'); var list = $('#list'); var items = '<ul>'; for (i=0; i<1000; i++) {

items += '<li class="item' + i + '">item</li>'; } items += '</ul>'; list.html (items); for (i=0; i<1000; i++) {

var s = $('.item' + i); } console.timeEnd('class'); console.time('id'); var list = $('#list'); var items = '<ul>'; for (i=0; i<1000; i++) {

items += '<li id="item' + i + '">item</li>'; } items += '</ul>'; list.html (items); for (i=0; i<1000; i++) {

var s = $('#item' + i); } console.timeEnd('id');

Page 28: Being a tweaker   modern web performance techniques

USE IDS NOT CLASSES

Page 29: Being a tweaker   modern web performance techniques

GIVE SELECTORS CONTEXT

$(“.class”).takeAction({x:y});

Vs

$(“.class”, “#container”).takeAction({x:y});

Page 30: Being a tweaker   modern web performance techniques

CACHE & CHAIN$(“.class”).takeAction1({x:y});$(“.class”).takeAction2({x:y});$(“.class”).takeAction2({x:y});

Vs

$(“.class”).takeAction1({x:y}) .takeAction2({x:y}) .takeAction3({x:y});

Page 31: Being a tweaker   modern web performance techniques

CACHE & CHAINfor (var i=0; i<1000; i++) {

$('#list').append (i); }

// much better this way var item = $('#list'); for (var i=0; i<1000; i++) {

item.append (i); }

Page 32: Being a tweaker   modern web performance techniques

AVOID DOM MANIPULATION

var list = ''; for (var i=0; i<1000; i++) {

list += '<li>'+i+'</li>'; } ('#list').html (list);

Page 33: Being a tweaker   modern web performance techniques

JOIN NOT CONCATvar array = []; for (var i=0; i<=10000; i++) {

array[i] = '<li>'+i+'</li>'; } $('#list').html (array.join (''));

Page 34: Being a tweaker   modern web performance techniques

RETURN FALSE$('#item').click (function () { // stuff here

return false; });