SlideShare a Scribd company logo
JavaScript
Performance



                        stevesouders.com/docs/sfjs-20120112.pptx
      Disclaimer: This content does not necessarily reflect the opinions of my employer.
YSlow   Cuzillion SpriteMe Hammerhead
Web
WPO       Performance
          Optimization
drives traffic
improves UX
increases revenue
reduces costs
What’s the #1
cause of slow
web pages?
JAVASCRIPT!
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
all requests containing “.js” are skipped
http://httparchive.org/trends.php?s=intersection
1995: scripts in HEAD
  <head>
  <script src=‘a.js’></script>
  </head>
blocks other downloads (IE 6-7, images
  in IE, iframes)
downloaded sequentially (IE 6-7)
blocks rendering during download &
  parse-execute
2007: move scripts to bottom
   ...
   <script src=‘a.js’></script>
   </body>
 doesn’t block other downloads
 downloaded sequentially in IE 6-7
 blocks rendering during download &
   parse-execute
2009: load scripts async
  var se =
   document.createElement(‘script’)
   ;
  se.src = ‘a.js’;
  document.getElementsByTagName(‘he
   ad’)[0].appendChild(se);

doesn’t block other downloads
downloaded in parallel (all browsers)
blocks rendering during parse-execute
2010: async + on-demand exec
   var se = new Image(); // Object
   se.onload = registerScript;
   se.src = ‘a.js’;

 separate download from parse-execute
 doesn’t block other downloads
 downloaded in parallel (all browsers)
 doesn’t block rendering until demanded
20??: markup
script async & defer
parsing doesn’t wait for script:
  • async – executed when available
  • defer – executed when parsing finished
when is it downloaded?




missing:
  • defer download AND execution
  • async/defer download, execute on demand
20??: markup
  <script src=‘a.js’
   [async|defer|noexecute]
   [deferdownload]>
doesn’t block downloads
downloaded in parallel
doesn’t block rendering until demanded
doesn’t contend for a connection
easier
ControlJS
  a JavaScript module for making scripts load faster

just change HTML
inline & external scripts
  <script type=‘text/cjs’
          data-cjssrc=‘main.js’>
  </script>

  <script type=‘text/cjs’>
  var name = getName();
  </script>
 http://controljs.org/
ControlJS
  a JavaScript module for making scripts load faster

download without executing
  <script type=‘text/cjs’
          data-cjssrc=‘main.js’
          data-cjsexec=false>
  <script>


Later if/when needed:
  CJS.execScript(src);
GMail Mobile
<script type=‘text/javascript’>
/*
var ...
*/
</script>

get script DOM element's text
remove comments
eval() when invoked
awesome for prefetching JS that might
  (not) be needed
http://goo.gl/l5ZLQ
localStorage
yuiblog.com/blog/2007/01/04/performance-research-part-2/
blaze.io/mobile/understanding-mobile-cache-sizes/
Home screen apps on iPhone are slower
because resources are re-requested
even though they should be read from
cache.
localStorage
window.localStorage:
   setItem()
   getItem()
   removeItem()
   clear()
also sessionStorage
all popular browsers, 5MB max
http://dev.w3.org/html5/webstorage/
http://diveintohtml5.org/storage.html
localStorage as cache
1st doc: write JS & CSS blocks to localStorage
   mres.-0yDUQJ03U8Hjija: <script>(function(){...

set cookie with entries & version
   MRES=-0yDUQJ03U8Hjija:-4EaJoFuDoX0iloI:...

later docs: read JS & CSS from localStorage
   document.write( localStorage.getItem(mres.-
     0yDUQJ03U8Hjija) );


http://stevesouders.com/blog/2011/03/28/storager-case-
  study-bing-google/
Google Analytics Async Snippet

var ga = document.createElement(‘script’);
ga.type = ‘text/javascript’;
ga.async = true;
ga.src = (‘https:’ ==
  document.location.protocol ? ‘https://ssl’ :
  ‘http://www’)+‘.google-analytics.com/ga.js’;
var s =
  document.getElementsByTagName(‘script’)[
  0];
s.parentNode.insertBefore(ga, s);

code.google.com/apis/analytics/docs/tracking/asyncTracking.html
var ga = document.createElement(‘script’);
ga.type = ‘text/javascript’;
ga.async = true;
ga.src = (‘https:’ ==
  document.location.protocol ? ‘https://ssl’ :
  ‘http://www’)+‘.google-analytics.com/ga.js’;
var s =
  document.getElementsByTagName(‘script’)[
  0];
s.parentNode.insertBefore(ga, s);
avoid mixed content warning
protocol relative URLs have problems
set src last
stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/
var ga = document.createElement(‘script’);
ga.type = ‘text/javascript’;
ga.async = true;
ga.src = (‘https:’ ==
  document.location.protocol ? ‘https://ssl’ :
  ‘http://www’)+‘.google-analytics.com/ga.js’;
var s =
  document.getElementsByTagName(‘script’)[
  0];
s.parentNode.insertBefore(ga, s);
previously:
   getElementsByTagName(‘head’)[0].
   appendChild(ga)
HEAD might not exist
stevesouders.com/blog/2010/05/11/appendchild-vs-insertbefore/
    Android 1.5, iPhone 3.0, Opera 8.50, Safari 3.2
stevesouders.com/blog/2010/05/12/autohead-my-first-browserscope-user-test/
var ga = document.createElement(‘script’);
ga.type = ‘text/javascript’;
ga.async = true;
ga.src = (‘https:’ ==
  document.location.protocol ? ‘https://ssl’ :
  ‘http://www’)+‘.google-analytics.com/ga.js’;
var s =
  document.getElementsByTagName(‘script’)[
  0];
s.parentNode.insertBefore(ga, s);
some browsers preserve execution order
    Firefox 3.6, Opera, OmniWeb



stevesouders.com/tests/jsorder.php
stevesouders.com/tests/jsorder.php
JavaScript Performance (at SFJS)
var ga = document.createElement(‘script’);
ga.type = ‘text/javascript’;
ga.async = true;
ga.src = (‘https:’ ==
  document.location.protocol ? ‘https://ssl’ :
  ‘http://www’)+‘.google-analytics.com/ga.js’;
var s =
  document.getElementsByTagName(‘script’)[
  0];
s.parentNode.insertBefore(ga, s);
some browsers preserve execution order
    Firefox 3.6, Opera, OmniWeb
async=true fixes this (except Opera)

stevesouders.com/tests/jsorder.php
<html>
  <head>
            A
     <link rel=stylesheet ...>
     <style>...</style>
     <script [...]></script>
            B
  </head>
  <body>
     <div>
     <p>
     <ul>
             C
  </body>
</html>

onload:      D
A




    script loads sooner
    beacon fires sooner
    blocks other async (Opera)
    may block rendering
B

    script loads later
    beacon fires later
    blocks fewer async (Opera)
    may block rendering
script loads last
    beacon fires late
    doesn’t block async
C   doesn’t block rendering
script loads after page
    beacon fires very late
    doesn’t block async
    doesn’t block rendering
    onload fires sooner
D
more
JavaScript Performance (at SFJS)
stevesouders.com/blog/2011/12/01/silk-ipad-galaxy-comparison/
stevesouders.com/mobileperf/mobileperfbkm.php
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
Top 100




Top 1000
JavaScript Performance (at SFJS)
takeaways
WPO                GA snippet is good
WebPagetest.org    Loadtimer.org
Cuzillion.com      MobilePerf.org
Browserscope.org   HTTPArchive.org
ControlJS.org      Velocity
localStorage       stevesouders.com
@souders
http://stevesouders.com/docs/sfjs-20120112.pptx

More Related Content

What's hot (20)

PPTX
@media - Even Faster Web Sites
Steve Souders
 
PPT
Web 2.0 Expo: Even Faster Web Sites
Steve Souders
 
PPTX
How fast are we going now?
Steve Souders
 
PPTX
Web Directions South - Even Faster Web Sites
Steve Souders
 
PDF
Metrics of Joy
Steve Souders
 
PPTX
Your Script Just Killed My Site
Steve Souders
 
PPTX
do u webview?
Steve Souders
 
PDF
Preconnect, prefetch, prerender...
MilanAryal
 
PPTX
High Performance Snippets
Steve Souders
 
PPTX
Browser Wars Episode 1: The Phantom Menace
Nicholas Zakas
 
PDF
Frontend SPOF
Patrick Meenan
 
PDF
Progressive Enhancement 2.0 (Conference Agnostic)
Nicholas Zakas
 
PPTX
Website performance optimisation
Webstock
 
PPT
Oscon 20080724
linkedin_resptest2
 
PDF
[jqconatx] Adaptive Images for Responsive Web Design
Christopher Schmitt
 
PPTX
High Performance JavaScript (CapitolJS 2011)
Nicholas Zakas
 
PPT
Widget Summit 2008
Volkan Unsal
 
PPT
Web20expo 20080425
Media Gorod
 
PDF
Mobile Web Speed Bumps
Nicholas Zakas
 
PDF
Java REST API Framework Comparison - PWX 2021
Matt Raible
 
@media - Even Faster Web Sites
Steve Souders
 
Web 2.0 Expo: Even Faster Web Sites
Steve Souders
 
How fast are we going now?
Steve Souders
 
Web Directions South - Even Faster Web Sites
Steve Souders
 
Metrics of Joy
Steve Souders
 
Your Script Just Killed My Site
Steve Souders
 
do u webview?
Steve Souders
 
Preconnect, prefetch, prerender...
MilanAryal
 
High Performance Snippets
Steve Souders
 
Browser Wars Episode 1: The Phantom Menace
Nicholas Zakas
 
Frontend SPOF
Patrick Meenan
 
Progressive Enhancement 2.0 (Conference Agnostic)
Nicholas Zakas
 
Website performance optimisation
Webstock
 
Oscon 20080724
linkedin_resptest2
 
[jqconatx] Adaptive Images for Responsive Web Design
Christopher Schmitt
 
High Performance JavaScript (CapitolJS 2011)
Nicholas Zakas
 
Widget Summit 2008
Volkan Unsal
 
Web20expo 20080425
Media Gorod
 
Mobile Web Speed Bumps
Nicholas Zakas
 
Java REST API Framework Comparison - PWX 2021
Matt Raible
 

Similar to JavaScript Performance (at SFJS) (20)

PDF
Webpack
Sofian Hadiwijaya
 
PDF
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
tdc-globalcode
 
PPTX
"Your script just killed my site" by Steve Souders
Dmitry Makarchuk
 
PDF
Progressive Web Apps
FITC
 
PDF
Front End Development for Back End Java Developers - Jfokus 2020
Matt Raible
 
PDF
Packing it all: JavaScript module bundling from 2000 to now
Derek Willian Stavis
 
PDF
Webpack packing it all
Criciúma Dev
 
PPT
Os mobile
jimlindforpope
 
PPT
Os mobile
jimlindforpope
 
PPT
Testable client side_mvc_apps_in_javascript
Timothy Oxley
 
PPT
Os mobile
jimlindforpope
 
PDF
Build Better Responsive websites. Hrvoje Jurišić
MeetMagentoNY2014
 
PDF
The Future of CSS with Web components
devObjective
 
PDF
The Future of CSS with Web Components
ColdFusionConference
 
PDF
Web-Performance
Walter Ebert
 
PPTX
Google I/O 2012 - Protecting your user experience while integrating 3rd party...
Patrick Meenan
 
PPT
Build Your Own CMS with Apache Sling
Bob Paulin
 
PDF
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
beyond tellerrand
 
PPT
Sanjeev ghai 12
Praveen kumar
 
PPTX
JavaScript Performance Patterns
Stoyan Stefanov
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
tdc-globalcode
 
"Your script just killed my site" by Steve Souders
Dmitry Makarchuk
 
Progressive Web Apps
FITC
 
Front End Development for Back End Java Developers - Jfokus 2020
Matt Raible
 
Packing it all: JavaScript module bundling from 2000 to now
Derek Willian Stavis
 
Webpack packing it all
Criciúma Dev
 
Os mobile
jimlindforpope
 
Os mobile
jimlindforpope
 
Testable client side_mvc_apps_in_javascript
Timothy Oxley
 
Os mobile
jimlindforpope
 
Build Better Responsive websites. Hrvoje Jurišić
MeetMagentoNY2014
 
The Future of CSS with Web components
devObjective
 
The Future of CSS with Web Components
ColdFusionConference
 
Web-Performance
Walter Ebert
 
Google I/O 2012 - Protecting your user experience while integrating 3rd party...
Patrick Meenan
 
Build Your Own CMS with Apache Sling
Bob Paulin
 
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
beyond tellerrand
 
Sanjeev ghai 12
Praveen kumar
 
JavaScript Performance Patterns
Stoyan Stefanov
 
Ad

More from Steve Souders (11)

PPTX
Make JavaScript Faster
Steve Souders
 
PPTX
The Perception of Speed
Steve Souders
 
PPTX
High Performance Web Components
Steve Souders
 
PPTX
Cache is King
Steve Souders
 
PPTX
Souders WPO Web 2.0 Expo
Steve Souders
 
PPTX
JSConf US 2010
Steve Souders
 
PDF
CouchDB Google
Steve Souders
 
PPT
Even Faster Web Sites at jQuery Conference '09
Steve Souders
 
PPTX
Browserscope Launch at TAE
Steve Souders
 
PPT
Even Faster Web Sites at The Ajax Experience
Steve Souders
 
PPT
SXSW: Even Faster Web Sites
Steve Souders
 
Make JavaScript Faster
Steve Souders
 
The Perception of Speed
Steve Souders
 
High Performance Web Components
Steve Souders
 
Cache is King
Steve Souders
 
Souders WPO Web 2.0 Expo
Steve Souders
 
JSConf US 2010
Steve Souders
 
CouchDB Google
Steve Souders
 
Even Faster Web Sites at jQuery Conference '09
Steve Souders
 
Browserscope Launch at TAE
Steve Souders
 
Even Faster Web Sites at The Ajax Experience
Steve Souders
 
SXSW: Even Faster Web Sites
Steve Souders
 
Ad

Recently uploaded (20)

PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
Designing Production-Ready AI Agents
Kunal Rai
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
July Patch Tuesday
Ivanti
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Biography of Daniel Podor.pdf
Daniel Podor
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Designing Production-Ready AI Agents
Kunal Rai
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 

JavaScript Performance (at SFJS)

  • 1. JavaScript Performance stevesouders.com/docs/sfjs-20120112.pptx Disclaimer: This content does not necessarily reflect the opinions of my employer.
  • 2. YSlow Cuzillion SpriteMe Hammerhead
  • 3. Web WPO Performance Optimization drives traffic improves UX increases revenue reduces costs
  • 4. What’s the #1 cause of slow web pages?
  • 8. all requests containing “.js” are skipped
  • 10. 1995: scripts in HEAD <head> <script src=‘a.js’></script> </head> blocks other downloads (IE 6-7, images in IE, iframes) downloaded sequentially (IE 6-7) blocks rendering during download & parse-execute
  • 11. 2007: move scripts to bottom ... <script src=‘a.js’></script> </body> doesn’t block other downloads downloaded sequentially in IE 6-7 blocks rendering during download & parse-execute
  • 12. 2009: load scripts async var se = document.createElement(‘script’) ; se.src = ‘a.js’; document.getElementsByTagName(‘he ad’)[0].appendChild(se); doesn’t block other downloads downloaded in parallel (all browsers) blocks rendering during parse-execute
  • 13. 2010: async + on-demand exec var se = new Image(); // Object se.onload = registerScript; se.src = ‘a.js’; separate download from parse-execute doesn’t block other downloads downloaded in parallel (all browsers) doesn’t block rendering until demanded
  • 15. script async & defer parsing doesn’t wait for script: • async – executed when available • defer – executed when parsing finished when is it downloaded? missing: • defer download AND execution • async/defer download, execute on demand
  • 16. 20??: markup <script src=‘a.js’ [async|defer|noexecute] [deferdownload]> doesn’t block downloads downloaded in parallel doesn’t block rendering until demanded doesn’t contend for a connection easier
  • 17. ControlJS a JavaScript module for making scripts load faster just change HTML inline & external scripts <script type=‘text/cjs’ data-cjssrc=‘main.js’> </script> <script type=‘text/cjs’> var name = getName(); </script> http://controljs.org/
  • 18. ControlJS a JavaScript module for making scripts load faster download without executing <script type=‘text/cjs’ data-cjssrc=‘main.js’ data-cjsexec=false> <script> Later if/when needed: CJS.execScript(src);
  • 19. GMail Mobile <script type=‘text/javascript’> /* var ... */ </script> get script DOM element's text remove comments eval() when invoked awesome for prefetching JS that might (not) be needed http://goo.gl/l5ZLQ
  • 23. Home screen apps on iPhone are slower because resources are re-requested even though they should be read from cache.
  • 24. localStorage window.localStorage: setItem() getItem() removeItem() clear() also sessionStorage all popular browsers, 5MB max http://dev.w3.org/html5/webstorage/ http://diveintohtml5.org/storage.html
  • 25. localStorage as cache 1st doc: write JS & CSS blocks to localStorage mres.-0yDUQJ03U8Hjija: <script>(function(){... set cookie with entries & version MRES=-0yDUQJ03U8Hjija:-4EaJoFuDoX0iloI:... later docs: read JS & CSS from localStorage document.write( localStorage.getItem(mres.- 0yDUQJ03U8Hjija) ); http://stevesouders.com/blog/2011/03/28/storager-case- study-bing-google/
  • 26. Google Analytics Async Snippet var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’)+‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[ 0]; s.parentNode.insertBefore(ga, s); code.google.com/apis/analytics/docs/tracking/asyncTracking.html
  • 27. var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’)+‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[ 0]; s.parentNode.insertBefore(ga, s); avoid mixed content warning protocol relative URLs have problems set src last stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/
  • 28. var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’)+‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[ 0]; s.parentNode.insertBefore(ga, s); previously: getElementsByTagName(‘head’)[0]. appendChild(ga) HEAD might not exist stevesouders.com/blog/2010/05/11/appendchild-vs-insertbefore/ Android 1.5, iPhone 3.0, Opera 8.50, Safari 3.2 stevesouders.com/blog/2010/05/12/autohead-my-first-browserscope-user-test/
  • 29. var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’)+‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[ 0]; s.parentNode.insertBefore(ga, s); some browsers preserve execution order Firefox 3.6, Opera, OmniWeb stevesouders.com/tests/jsorder.php
  • 32. var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’)+‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[ 0]; s.parentNode.insertBefore(ga, s); some browsers preserve execution order Firefox 3.6, Opera, OmniWeb async=true fixes this (except Opera) stevesouders.com/tests/jsorder.php
  • 33. <html> <head> A <link rel=stylesheet ...> <style>...</style> <script [...]></script> B </head> <body> <div> <p> <ul> C </body> </html> onload: D
  • 34. A script loads sooner beacon fires sooner blocks other async (Opera) may block rendering
  • 35. B script loads later beacon fires later blocks fewer async (Opera) may block rendering
  • 36. script loads last beacon fires late doesn’t block async C doesn’t block rendering
  • 37. script loads after page beacon fires very late doesn’t block async doesn’t block rendering onload fires sooner D
  • 38. more
  • 48. takeaways WPO GA snippet is good WebPagetest.org Loadtimer.org Cuzillion.com MobilePerf.org Browserscope.org HTTPArchive.org ControlJS.org Velocity localStorage stevesouders.com

Editor's Notes

  • #2: Permission to use photo given by Amnemona: http://www.flickr.com/photos/marinacvinhal/379111290/
  • #3: flickr.com/photos/bekahstargazing/318930460/
  • #4: flickr.com/photos/pedromourapinheiro/3123885534/
  • #5: http://www.flickr.com/photos/peterblapps/838125790/
  • #6: http://www.flickr.com/photos/salty_soul/5799650534/
  • #8: 3.777 seconds - http://www.webpagetest.org/result/120111_0P_2TW4Q/ - block “.js” (it’s not downloaded)5.471 seconds - http://www.webpagetest.org/result/120111_GR_2TW90/Alexa top 100wwide
  • #9: median: 3.650vs 2.4873.777 seconds - http://www.webpagetest.org/result/120111_0P_2TW4Q/ - block “.js” (it’s not downloaded)5.471 seconds - http://www.webpagetest.org/result/120111_GR_2TW90/Alexa top 100wwide
  • #16: flickr.com/photos/gevertulley/4771808965/Generallyasync &amp; defer scripts start downloading immediately. I wish they’d wait, esp. defer scripts, so they don’t hog connections from the limited pool.subatomic particle traces
  • #20: GMail Mobile: http://googlecode.blogspot.com/2009/09/gmail-for-mobile-html5-series-reducing.htmlSproutCore: http://blog.sproutcore.com/post/225219087/faster-loading-through-eval
  • #21: flickr.com/photos/bryanpearson/564703455/
  • #25: flickr.com/photos/bryanpearson/564703455/
  • #26: flickr.com/photos/nelsoncruz/431244400/
  • #35: block other async scripts in Operaexecute ASAPsend beacon before leaving pageblock UI thread
  • #36: block other async scripts in Operaexecute ASAPsend beacon before leaving pageblock UI thread
  • #37: block other async scripts in Operaexecute ASAPsend beacon before leaving pageblock UI thread
  • #38: block other async scripts in Operaexecute ASAPsend beacon before leaving pageblock UI thread
  • #39: flickr.com/photos/dualphoto/2609096047/
  • #49: flickr.com/photos/myklroventine/4062102754/