Even Faster Web Sites at jQuery Conference '09
Upcoming SlideShare
Loading in...5
×
 

Even Faster Web Sites at jQuery Conference '09

on

  • 3,671 views

Even Faster Web Sites covering splitting the initial payload, loading scripts without blocking, and coupling asynchronous scripts.

Even Faster Web Sites covering splitting the initial payload, loading scripts without blocking, and coupling asynchronous scripts.

Statistics

Views

Total Views
3,671
Views on SlideShare
3,667
Embed Views
4

Actions

Likes
5
Downloads
45
Comments
0

1 Embed 4

http://www.slideshare.net 4

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • cc: http://www.flickr.com/photos/rollerfan/2868949733/
  • Data source: Steve Souders Tested on IE6 on Comcast cable modem (~5 mbps) medium powered PC, April 2008.
  • Ten top sites according to Alexa.com. Data source: Steve Souders Tested on IE6 on Comcast cable modem (~5 mbps) medium powered PC, April 2008. http://www.aol.com/ http://www.ebay.com/ http://www.facebook.com/ http://www.google.com/search?hl=en&q=flowers http://www.myspace.com/ http://www.msn.com/ http://search.live.com/results.aspx?q=flowers&mkt=en-us&scope=&FORM=LIVSOP http://en.wikipedia.org/wiki/Flowers http://www.yahoo.com/ http://www.youtube.com/ For Google and Live Search there are so few components (2-4) and they're mostly cacheable so the HTML document is a bigger percentage.
  • If you could cut performance in half, FE changes would be 40-45%, while BE would be only 5-10%. BE changes are typically more complex: rearchitecture, optimize code, add/modify hw, distribute databases, etc. FE is simpler: change web server config, place scripts and stylesheets differently in the page, combine requests, etc. I’ve worked with dev teams to cut response times on 50 properties, often by 25% or more. And feedback from other companies is similar. Permission to use photo given by Technicolor: http://flickr.com/photos/technicolor/44988148/
  • photo courtesy of Vicki & Chuck Rogers: http://www.flickr.com/photos/two-wrongs/205467442/
  • Data Source: Steve Souders aol 76% ebay 45% facebook 41% google 42% live search 9% msn 37% myspace 37% yahoo 45% youtube 60% wikipedia 26% average 42%
  • Data source: Steve Souders
  • Permission to use photo given by Brian.H - http://flickr.com/photos/robinofloxley/750220669/
  • Of the ten top sites, MSN.com (Script DOM Element), Live Search (Script in Iframe), and Yahoo (Script DOM Element) use advanced script loading techniques.
  • All of these allow for parallel downloads, but none of them allow for parallel JS execution – that's not possible (currently, WebKit is doing some stuff on that).
  • Audio (IE "click") is another busy indicator. Delayed rendering and delayed onload ("done") are other busy indicators. Sometimes busy indicators are bad, sometimes good.
  • Data source: Steve Souders Audio (IE "click") is another busy indicator. Delayed rendering and delayed onload ("done") are other busy indicators. Sometimes busy indicators are bad, sometimes good.
  • Data source: Steve Souders
  • I'll do JavaScript and PHP implementations of this logic soon.
  • Permission to use photo given by Reciprocity: http://flickr.com/photos/alanjaras/76000107/
  • Data source: Steve Souders
  • Newer browsers (IE8, Saf4, Chr2) work, but mainstream browsers need a workaround.
  • putting code in the script block doesn't work in any browser; you have to add stuff to the external script this doesn't load asynchronously
  • Newer browsers (IE8, Saf4, Chr2) work, but mainstream browsers need a workaround.
  • Newer browsers (IE8, Saf4, Chr2) work, but mainstream browsers need a workaround.
  • loadInterval is 420 ms
  • esp. good when your HTML document takes more than 10-20%, and when users have high latency.
  • 72 years = 2,270,592,000 seconds = 500ms * 4.4B page views
  • 72 years = 2,270,592,000 seconds = 500ms * 4.4B page views
  • 72 years = 2,270,592,000 seconds = 500ms * 4.4B page views
  • 72 years = 2,270,592,000 seconds = 500ms * 4.4B page views
  • "thank you" by nj dodge: http://flickr.com/photos/nj_dodge/187190601/

Even Faster Web Sites at jQuery Conference '09 Even Faster Web Sites at jQuery Conference '09 Presentation Transcript

  •  
  • the importance of frontend performance 17% 83% iGoogle, primed cache 9% 91% iGoogle, empty cache
  • time spent on the frontend April 2008 Empty Cache Primed Cache www.aol.com 97% 97% www.ebay.com 95% 81% www.facebook.com 95% 81% www.google.com/search 47% 0% search.live.com/results 67% 0% www.msn.com 98% 94% www.myspace.com 98% 98% en.wikipedia.org/wiki 94% 91% www.yahoo.com 97% 96% www.youtube.com 98% 97%
  • 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
  • 14 RULES
    • MAKE FEWER HTTP REQUESTS
    • USE A CDN
    • ADD AN EXPIRES HEADER
    • GZIP COMPONENTS
    • PUT STYLESHEETS AT THE TOP
    • PUT SCRIPTS AT THE BOTTOM
    • AVOID CSS EXPRESSIONS
    • MAKE JS AND CSS EXTERNAL
    • REDUCE DNS LOOKUPS
    • MINIFY JS
    • AVOID REDIRECTS
    • REMOVE DUPLICATE SCRIPTS
    • CONFIGURE ETAGS
    • MAKE AJAX CACHEABLE
  •  
    • Sept 2007
  •  
  •  
    • June 2009
  • Even Faster Web Sites Splitting the initial payload Loading scripts without blocking Coupling asynchronous scripts Positioning inline scripts Sharding dominant domains Flushing the document early Using iframes sparingly Simplifying CSS Selectors Understanding Ajax performance.......... Doug Crockford Creating responsive web apps............ Ben Galbraith, Dion Almaer Writing efficient JavaScript............. Nicholas Zakas Scaling with Comet..................... Dylan Schiemann Going beyond gzipping............... Tony Gentilcore Optimizing images................... Stoyan Stefanov, Nicole Sullivan
  • Why focus on JavaScript? AOL eBay Facebook MySpace Wikipedia Yahoo! YouTube
  • scripts block <script src=&quot;A.js&quot;> blocks parallel downloads and rendering 7 secs: IE 8, FF 3.5, Chr 2, Saf 4 9 secs: IE 6-7, FF 3.0, Chr 1, Op 9-10, Saf 3
  • initial payload and execution 26% avg 252K avg JavaScript Functions Executed before onload www.aol.com 115K 30% www.ebay.com 183K 44% www.facebook.com 1088K 9% www.google.com/search 15K 45% search.live.com/results 17K 24% www.msn.com 131K 31% www.myspace.com 297K 18% en.wikipedia.org/wiki 114K 32% www.yahoo.com 321K 13% www.youtube.com 240K 18%
  • splitting the initial payload split your JavaScript between what's needed to render the page and everything else load &quot;everything else&quot; after the page is rendered separate manually (Page Speed); tools needed to automate this (Microsoft Doloto) load scripts without blocking – how?
  • MSN.com: parallel scripts Scripts and other resources downloaded in parallel! How? Secret sauce?! var p= g.getElementsByTagName(&quot;HEAD&quot;)[0]; var c=g.createElement(&quot;script&quot;); c.type=&quot;text/javascript&quot;; c.onreadystatechange=n; c.onerror=c.onload=k; c.src=e; p.appendChild(c) MSN
  • Loading Scripts Without Blocking XHR Eval XHR Injection Script in Iframe Script DOM Element Script Defer document.write Script Tag
  • XHR Eval script must have same domain as main page must refactor script var xhrObj = getXHRObject(); xhrObj.onreadystatechange = function() { if ( xhrObj.readyState != 4 ) return; eval(xhrObj.responseText); }; xhrObj.open('GET', 'A.js', true); xhrObj.send('');
  • XHR Injection var xhrObj = getXHRObject(); xhrObj.onreadystatechange = function() { if ( xhrObj.readyState != 4 ) return; var se=document.createElement('script'); document.getElementsByTagName('head') [0].appendChild(se); se.text = xhrObj.responseText; }; xhrObj.open('GET', 'A.js', true); xhrObj.send(''); script must have same domain as main page
  • Script in Iframe <iframe src='A.html' width=0 height=0 frameborder=0 id=frame1></iframe>
    • iframe must have same domain as main page
    • must refactor script:
      • // access iframe from main page
      • window.frames[0].createNewDiv();
      • // access main page from iframe
      • parent.document.createElement('div');
  • Script DOM Element var se = document.createElement('script'); se.src = 'http://anydomain.com/A.js'; document.getElementsByTagName('head') [0].appendChild(se); script and main page domains can differ no need to refactor JavaScript
  • Script Defer <script defer src='A.js'></script> supported in IE and FF 3.1+ script and main page domains can differ no need to refactor JavaScript
  • document.write Script Tag document.write (&quot;<script type='text/javascript' src='A.js'> </script>&quot;); parallelization only works in IE parallel downloads for scripts, nothing else all document.write s must be in same script block
  • browser busy indicators
  • browser busy indicators good to show busy indicators when the user needs feedback bad when downloading in the background
  • ensure/avoid ordered execution
    • Ensure scripts execute in order:
      • necessary when scripts have dependencies
      • IE: http://stevesouders.com/cuzillion/?ex=10017
      • FF: http://stevesouders.com/cuzillion/?ex=10018
    • Avoid scripts executing in order:
      • faster – first script back is executed immediately
      • http://stevesouders.com/cuzillion/?ex=10019
  • Load Scripts Without Blocking * Only other document.write scripts are downloaded in parallel (in the same script block).
  • and the winner is... XHR Eval XHR Injection Script in iframe Script DOM Element Script Defer Script DOM Element Script Defer Script DOM Element Script DOM Element (FF) Script Defer (IE) XHR Eval XHR Injection Script in iframe Script DOM Element (IE) XHR Injection XHR Eval Script DOM Element (IE) Managed XHR Injection Managed XHR Eval Script DOM Element Managed XHR Injection Managed XHR Eval Script DOM Element (FF) Script Defer (IE) Managed XHR Eval Managed XHR Injection Script DOM Element (FF) Script Defer (IE) Managed XHR Eval Managed XHR Injection different domains same domains no order preserve order no order no busy show busy show busy no busy preserve order
  • Loading Scripts Without Blocking
    • don't let scripts block other downloads
    • you can still control execution order, busy indicators, and onload event
    • What about inline scripts?
  • menu.js image.gif
  • synchronous JS example: menu.js
    • <script src=&quot;menu.js&quot; type=&quot;text/javascript&quot;></script>
    • <script type=&quot;text/javascript&quot;>
    • var aExamples =
    • [
    • ['couple-normal.php', 'Normal Script Src'],
    • ['couple-xhr-eval.php', 'XHR Eval'],
    • ...
    • ['managed-xhr.php', 'Managed XHR']
    • ];
    • function init() {
    • EFWS.Menu.createMenu('examplesbtn', aExamples);
    • }
    • init();
    • </script>
  • asynchronous JS example: menu.js
    • <script type=&quot;text/javascript&quot;>
    • var domscript = document.createElement('script');
    • domscript.src = &quot;menu.js&quot;;
    • document.getElementsByTagName('head')[0].appendChild(domscript);
    • var aExamples =
    • [
    • ['couple-normal.php', 'Normal Script Src'],
    • ['couple-xhr-eval.php', 'XHR Eval'],
    • ...
    • ['managed-xhr.php', 'Managed XHR']
    • ];
    • function init() {
    • EFWS.Menu.createMenu('examplesbtn', aExamples);
    • }
    • init();
    • </script>
    script DOM element approach
  • before after menu.js image.gif menu.js image.gif
  • Loading Scripts Without Blocking * Only other document.write scripts are downloaded in parallel (in the same script block). !IE
    • what about
    • inlined code
    • that depends on the script?
  • baseline coupling results (not good) * Scripts download in parallel regardless of the Defer attribute. need a way to load scripts asynchronously AND preserve order
  • coupling techniques
    • hardcoded callback
    • window onload
    • timer
    • degrading script tags
    • script onload
  • technique 1: hardcoded callback
    • <script type=&quot;text/javascript&quot;>
    • var aExamples = [['couple-normal.php', 'Normal Script Src'], ...];
    • function init() {
    • EFWS.Menu.createMenu('examplesbtn', aExamples);
    • }
    • var domscript = document.createElement('script');
    • domscript.src = &quot;menu.js&quot;;
    • document.getElementsByTagName('head')[0].appendChild(domscript);
    • </script>
    • init() is called from within menu.js
    • not very flexible
    • doesn't work for 3 rd party scripts
  • technique 2: window onload
    • <iframe src=&quot;menu.php&quot; width=0 height=0 frameborder=0> </iframe>
    • <script type=&quot;text/javascript&quot;>
    • var aExamples = [['couple-normal.php', 'Normal Script Src'], ...];
    • function init() {
    • EFWS.Menu.createMenu('examplesbtn', aExamples);
    • }
    • if ( window.addEventListener ) {
    • window.addEventListener(&quot;load&quot;, init, false);
    • }
    • else if ( window.attachEvent ) {
    • window.attachEvent(&quot;onload&quot;, init);
    • }
    • </script>
    • init() is called at window onload
    • must use async technique that blocks onload:
      • Script in Iframe does this across most browsers
    • init() called later than necessary
  • technique 3: timer
    • <script type=&quot;text/javascript&quot;>
    • var domscript = document.createElement('script');
    • domscript.src = &quot;menu.js&quot;;
    • document.getElementsByTagName('head')[0].appendChild(domscript);
    • var aExamples = [['couple-normal.php', 'Normal Script Src'], ...];
    • function init() {
    • EFWS.Menu.createMenu('examplesbtn', aExamples);
    • }
    • function initTimer(interval) {
    • if ( &quot;undefined&quot; === typeof(EFWS) ) {
    • setTimeout(initTimer, interval);
    • }
    • else {
    • init();
    • }
    • }
    • initTimer(300);
    • </script>
    • load if interval too low, delay if too high
    • slight increased maintenance – EFWS
  • John Resig's degrading script tags
    • <script src=&quot;menu-degrading.js&quot; type=&quot;text/javascript&quot;>
    • var aExamples = [['couple-normal.php', 'Normal Script Src'], ...];
    • function init() {
    • EFWS.Menu.createMenu('examplesbtn', aExamples);
    • }
    • init();
    • </script>
    at the end of menu-degrading.js: var scripts = document.getElementsByTagName(&quot;script&quot;); var cntr = scripts.length; while ( cntr ) { var curScript = scripts[cntr-1]; if (curScript.src.indexOf(&quot;menu-degrading.js&quot;) != -1) { eval( curScript.innerHTML ); break; } cntr--; } http://ejohn.org/blog/degrading-script-tags/ cleaner clearer safer – inlined code not called if script fails no browser supports it
  • technique 4: degrading script tags
    • <script type=&quot;text/javascript&quot;>
    • var aExamples = [['couple-normal.php', 'Normal Script Src'],...];
    • function init() {
    • EFWS.Menu.createMenu('examplesbtn', aExamples);
    • }
    • var domscript = document.createElement('script');
    • domscript.src = &quot;menu-degrading.js&quot;;
    • if ( -1 != navigator.userAgent.indexOf(&quot;Opera&quot;) ) {
    • domscript.innerHTML = &quot;init();&quot;;
    • }
    • else {
    • domscript.text = &quot;init();&quot;;
    • }
    • document.getElementsByTagName('head')[0].appendChild(domscript);
    • </script>
    • elegant, flexible (cool!)
    • not well known
    • doesn't work for 3 rd party scripts (unless...)
  • technique 5: script onload
    • <script type=&quot;text/javascript&quot;>
    • var aExamples = [['couple-normal.php', 'Normal Script Src'], ...];
    • function init() {
    • EFWS.Menu.createMenu('examplesbtn', aExamples);
    • }
    • var domscript = document.createElement('script');
    • domscript.src = &quot;menu.js&quot;;
    • domscript.onloadDone = false;
    • domscript.onload = function() {
    • if ( ! domscript.onloadDone ) { init(); }
    • domscript.onloadDone = true;
    • };
    • domscript.onreadystatechange = function() {
    • if ( &quot;loaded&quot; === domscript.readyState ) {
    • if ( ! domscript.onloadDone ) { init(); }
    • domscript.onloadDone = true;
    • }
    • }
    • document.getElementsByTagName('head')[0].appendChild(domscript);
    • </script>
    • pretty nice, medium complexity
    menu.js image.gif
    • what about
    • multiple scripts
    • that depend on each other,
    • and inlined code
    • that depends on the scripts?
    • two solutions:
      • Managed XHR
      • DOM Element and Doc Write
  • multiple script example: menutier.js
    • <script src=&quot;menu.js&quot; type=&quot;text/javascript&quot;></script>
    • <script src=&quot;menutier.js&quot; type=&quot;text/javascript&quot;></script>
    • <script type=&quot;text/javascript&quot;>
    • var aRaceConditions = [['couple-normal.php', 'Normal...];
    • var aWorkarounds = [['hardcoded-callback.php', 'Hardcod...];
    • var aMultipleScripts = [['managed-xhr.php', 'Managed XH...];
    • var aLoadScripts = [['loadscript.php', 'loadScript'], ...];
    • var aSubmenus =
    • [[&quot;Race Conditions&quot;, aRaceConditions],
    • [&quot;Workarounds&quot;, aWorkarounds],
    • [&quot;Multiple Scripts&quot;, aMultipleScripts],
    • [&quot;General Solution&quot;, aLoadScripts]];
    • function init() {
    • EFWS.Menu.createTieredMenu('examplesbtn', aSubmenus);
    • }
    • </script>
  • technique 1: managed XHR
    • <script type=&quot;text/javascript&quot;>
    • var aRaceConditions = [['couple-normal.php', 'Normal...];
    • var aWorkarounds = [['hardcoded-callback.php', 'Hardcod...];
    • var aMultipleScripts = [['managed-xhr.php', 'Managed XH...];
    • var aLoadScripts = [['loadscript.php', 'loadScript'], ...];
    • var aSubmenus = [[&quot;Race Conditions&quot;, aRaceConditions], ...];
    • function init() {
    • EFWS.Menu.createTieredMenu('examplesbtn', aSubmenus);
    • }
    • EFWS.Script.loadScriptXhrInjection(&quot;menu.js&quot;, null, true);
    • EFWS.Script.loadScriptXhrInjection(&quot;menutier.js&quot;, init, true);
    • </script>
    • XHR Injection asynchronous technique does not preserve order – we have to add that
    before after
  • EFWS.loadScriptXhrInjection
    • // Load an external script.
    • // Optionally call a callback and preserve order.
    • loadScriptXhrInjection: function(url, onload, bOrder) {
    • var iQ = EFWS.Script.queuedScripts.length;
    • if ( bOrder ) {
    • var qScript = { response: null, onload: onload, done: false };
    • EFWS.Script.queuedScripts[iQ] = qScript;
    • }
    • var xhrObj = EFWS.Script.getXHRObject();
    • xhrObj.onreadystatechange = function() {
    • if ( xhrObj.readyState == 4 ) {
    • if ( bOrder ) {
    • EFWS.Script.queuedScripts[iQ].response = xhrObj.responseText;
    • EFWS.Script.injectScripts();
    • }
    • else {
    • eval(xhrObj.responseText);
    • if ( onload ) {
    • onload();
    • }
    • }
    • }
    • };
    • xhrObj.open('GET', url, true);
    • xhrObj.send('');
    • }
    process queue (next slide) or... eval now, call callback save response to queue add to queue (if bOrder)
  • EFWS.injectScripts
    • // Process queued scripts to see if any are ready to inject.
    • injectScripts: function() {
    • var len = EFWS.Script.queuedScripts.length;
    • for ( var i = 0; i < len; i++ ) {
    • var qScript = EFWS.Script.queuedScripts[i];
    • if ( ! qScript.done ) {
    • if ( ! qScript.response ) {
    • // STOP! need to wait for this response
    • break;
    • }
    • else {
    • eval(qScript.response);
    • if ( qScript.onload ) {
    • qScript.onload();
    • }
    • qScript.done = true;
    • }
    • }
    • }
    • }
    preserves external script order non-blocking works in all browsers couples with inlined code works with scripts across domains ready for this script, eval and call callback bail – need to wait to preserve order if not yet injected
  • technique 2: DOM Element and Doc Write Firefox & Opera – use Script DOM Element IE – use document.write Script Tag Safari, Chrome – no benefit; rely on Safari 4 and Chrome 2
  • EFWS.loadScripts
    • loadScripts: function(aUrls, onload) {
    • // first pass: see if any of the scripts are on a different domain
    • var nUrls = aUrls.length;
    • var bDifferent = false;
    • for ( var i = 0; i < nUrls; i++ ) {
    • if ( EFWS.Script.differentDomain(aUrls[i]) ) {
    • bDifferent = true;
    • break;
    • }
    • }
    • // pick the best loading function
    • var loadFunc = EFWS.Script.loadScriptXhrInjection;
    • if ( bDifferent ) {
    • if ( -1 != navigator.userAgent.indexOf('Firefox') ||
    • -1 != navigator.userAgent.indexOf('Opera') ) {
    • loadFunc = EFWS.Script.loadScriptDomElement;
    • }
    • else {
    • loadFunc = EFWS.Script.loadScriptDocWrite;
    • }
    • }
    • // second pass: load the scripts
    • for ( var i = 0; i < nUrls; i++ ) {
    • loadFunc(aUrls[i], ( i+1 == nUrls ? onload : null ), true);
    • }
    • }
  • multiple scripts with dependencies
    • <script type=&quot;text/javascript&quot;>
    • var aRaceConditions = [['couple-normal.php', 'Normal...];
    • var aWorkarounds = [['hardcoded-callback.php', 'Hardcod...];
    • var aMultipleScripts = [['managed-xhr.php', 'Managed XH...];
    • var aLoadScripts = [['loadscript.php', 'loadScript'], ...];
    • var aSubmenus = [[&quot;Race Conditions&quot;, aRaceConditions], ...];
    • function init() {
    • EFWS.Menu.createTieredMenu('examplesbtn', aSubmenus);
    • }
    • EFWS.Script.loadScripts([&quot;menu.js&quot;, &quot;menutier.js&quot;], init);
    • </script>
    • scripts on same domain:
      • order preserved, no blocking
    • scripts on different domain:
      • order preserved: all
      • loads scripts in parallel: all except Saf3, Chr1
      • load script and image in parallel: FF, Saf4, Chr2
  • asynchronous scripts wrap-up
  • case study: Google Analytics
    • recommended pattern: 1
    • <script type=&quot;text/javascript&quot;>
    • var gaJsHost = ((&quot;https:&quot; == document.location.protocol) ? &quot;https://ssl.&quot; : &quot;http://www.&quot;);
    • document.write(unescape(&quot;%3Cscript src='&quot; + gaJsHost + &quot;google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E&quot;));
    • </script>
    • <script type=&quot;text/javascript&quot;>
    • var pageTracker = _gat._getTracker(&quot;UA-xxxxxx-x&quot;);
    • pageTracker._trackPageview();
    • </script>
    • document.write Script Tag approach blocks other resources
    1 http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55488
  • case study: dojox.analytics.Urchin 1
    • _loadGA: function(){
    • var gaHost = (&quot;https:&quot; == document.location.protocol) ?
    • &quot;https://ssl.&quot; : &quot;http://www.&quot;;
    • dojo.create('script', {
    • src: gaHost + &quot;google-analytics.com/ga.js&quot;
    • }, dojo.doc.getElementsByTagName(&quot;head&quot;)[0]);
    • setTimeout(dojo.hitch(this, &quot;_checkGA&quot;), this.loadInterval);
    • },
    • _checkGA: function(){
    • setTimeout(dojo.hitch(this, !window[&quot;_gat&quot;] ? &quot;_checkGA&quot; : &quot;_gotGA&quot;), this.loadInterval);
    • },
    • _gotGA: function(){
    • this.tracker = _gat._getTracker(this.acct); ...
    • }
    • Script DOM Element approach
    • &quot;timer&quot; coupling technique (script onload better)
    1 http://docs.dojocampus.org/dojox/analytics/Urchin
  • asynchronous loading & coupling
    • async technique: Script DOM Element
      • easy, cross-browser
      • doesn't ensure script order
    • coupling technique: script onload
      • fairly easy, cross-browser
      • ensures execution order for external script and inlined code
    • multiple interdependent external and inline scripts:
      • much more complex (see hidden slides)
      • concatenate your external scripts into one!
  • flushing the document early
    • gotchas:
      • PHP output_buffering – ob_flush()
      • Transfer-Encoding: chunked
      • gzip – Apache's DeflateBufferSize before 2.2.8
      • proxies and anti-virus software
      • browsers – Safari (1K), Chrome (2K)
    • other languages:
      • $| or FileHandle autoflush (Perl), flush (Python), ios.flush (Ruby)
    call PHP's flush() html image image script html image image script
  • flushing and domain blocking
    • you might need to move flushed resources to a domain different from the HTML doc
    blocked by HTML document different domains html image image script html image image script
  • successful flushing
    • Google Search
    • external resource downloaded early
    • content visible to the user
    http://www.google.com/images/nav_logo4.png google image image script image 204
  • performance analyzers (HPWS) YSlow Page Speed Pagetest VRTA neXpert combine JS & CSS X X X use CSS sprites X X use a CDN X X set Expires in the future X X X X X gzip text responses X X X X X put CSS at the top X X put JS at the bottom X avoid CSS expressions X X make JS & CSS external reduce DNS lookups X X minify JS X X X avoid redirects X X X X remove dupe scripts X remove ETags X X X
  • performance analyzers (EFWS) YSlow Page Speed Pagetest VRTA neXpert don't block UI thread split JS payload X load scripts async X inline JS b4 stylesheet X write efficient JS min. uncompressed size optimize images X X shard domains X X flush the document avoid iframes simplify CSS selectors X X
  • performance analyzers (other) YSlow Page Speed Pagetest VRTA neXpert use persistent conns X X X reduce cookies 2.0 X X X avoid net congestion X increase MTU, TCP win X avoid server congestion X remove unused CSS X specify image dims X use GET for Ajax 2.0 reduce DOM elements 2.0 avoid 404 errors 2.0 avoid Alpha filters 2.0 don't scale images 2.0 X optimize favicon 2.0
    • focus on the frontend
    • run YSlow ( http://developer.yahoo.com/yslow )
    • and Page Speed! ( http://code.google.com/speed/page-speed/ )
    • speed matters
    takeaways
    • Bing:
    • Yahoo:
    • Google:
    • AOL:
    • Shopzilla:
    impact on revenue 1 http://en.oreilly.com/velocity2009/public/schedule/detail/8523 2 http://www.slideshare.net/stoyan/yslow-20-presentation 3 http://en.oreilly.com/velocity2009/public/schedule/detail/7579 4 http://en.oreilly.com/velocity2009/public/schedule/detail/7709 +2000 ms  -4.3% revenue/user 1 +400 ms  -5-9% full-page traffic 2 +400 ms  -0.59% searches/user 1 fastest users  +50% page views 3 -5000 ms  +7-12% revenue 4
    • hardware – reduced load
      • Shopzilla – 50% fewer servers
    • bandwidth – reduced response size
    cost savings http://billwscott.com/share/presentations/2008/stanford/HPWP-RealWorld.pdf
    • if you want
      • better user experience
      • more revenue
      • reduced operating costs
    • the strategy is clear
    • Even Faster Web Sites
  • Steve Souders [email_address] http://stevesouders.com/docs/jquery-20090913.ppt