SlideShare a Scribd company logo
Third-Party Scripts
     and You
       Patrick Meenan
  pmeenan@webpagetest.org
        @patmeenan
The Performance Golden Rule

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




            www.flickr.com/photos/oreillyconf/6326167731/




   * http://www.stevesouders.com/blog/2012/02/10/the-performance-golden-rule/
Torbit Insight Real-User Data

                                                        …1,000 sites representing
                                                         6.7 billion pageviews…

                                                        …average 7% of load time
                                                         is spent on the backend
                                                        compared to a whopping
                                                          93% on the frontend.




    http://torbit.com/blog/2012/09/19/some-interesting-performance-statistics/
Base Page




            Time to First Byte

                                 4




                Actual back-end Time!
We can fix that!




http://www.flickr.com/photos/elsie/4742380987/
Social Widgets back-end API
 Call directly from your back-end
 Returns HTML to be injected directly into your page
 - echo file_get_contents(“http://social.patrickmeenan.com/gplus/?cookies=...”);


 Implementation details:
 - Synchronous and blocking
 - Do not cache the results
 - If you need to set a timeout, make sure it is at least 20 seconds, 45 preferred
 - Include all cookies sent from the client
 - May return javascript and set cookies
This Google guy is a
 complete nutter
 #velocityconf


Wow, to think I used to
respect @patmeenan
#velocityconf
But, that’s EXACTLY what this does…




     <scr i pt sr c=‘ … ’ ></ scr i pt >
                       …
The Victim
http://youtu.be/HSbHNIvhOFU
When the widget is unavailable…
http://youtu.be/3-zaos02CxI
Because of
     This:  <scr i pt
            sr c=‘ ht t ps: / / api s. googl e. com j s/ pl usone. j s’
                                                     /                       ></ scr i p
            t>
Instead of: <scr i pt >
             ( f unct i on( ) {
                  var po = docum       ent . cr eat eEl ement ( ‘ scr i pt   ’ );
                  po. sr c = ‘ ht t ps: / / api s. googl e. com j s/ pl
                                                                  /          usone. j s’ ;
                  var s = docum      ent . get El em ent sByTagNam ‘  e(     scr i pt ’ ) [ 0] ;
                  s. par ent Node. i nser t Bef or e( po, s) ;
               })();
            </ scr i pt >


 Or Even:    <scr i pt sr c=‘ ht t ps: / / api s. googl e. com j s/ pl usone. j s’ async
                                                              /
             def er ></ scr i pt >

                  http://www.stevesouders.com/blog/2009/12/01/google-analytics-goes-async/
And Monitoring Says…
• Server Monitoring
   Base page responded in 0.160 seconds
• Full-Browser Monitoring
   Page loaded in 25 seconds
• Analytics Page Views
   Loaded and executed asynchronously
• Real User Monitoring Performance Reporting
   No data if user bailed before onLoad
Loaded Asynchronously




                    http://youtu.be/krin-F65Fd8
Loaded Asynchronously




                    http://youtu.be/krin-F65Fd8
There’s More!
On that one page, all before the main content:

<scr i pt     sr c=‘ ht t p: / / code. j quer y. com j quer y-
                                                    /
1. 7. 1. mi   n. j s’ ></ scr i pt >
<scr i pt
sr c=‘ ht t   p: / / scr i pt s. ver t i cal acui t y. com vat / m
                                                          /       on/ vt . j s’ ></ scr i pt
>
<scr i pt     sr c=‘ ht t p: / / ak. sai l - hor i zon. com scout / v1. j s’ ></ scr i pt >
                                                           /
<scr i pt     sr c=‘ / / cdn. opt i m zel y. com j s/ xxxxx. j s’ ></ scr i pt >
                                      i             /
<scr i pt
sr c=‘ ht t   ps: / / pl at f or m t wi t t er . com anywher e. j s’ ></ scr i pt >
                                  .                 /
<scr i pt
sr c=‘ ht t   p: / / www. r eddi t . com st at i c/ but t on/ but t on1. j s’ ></ scr i pt >
                                         /
<scr i pt     sr c=‘ ht t p: / / wi dget s. di gg. com but t ons. j s’ ></ scr i pt >
                                                      /
Watch out for Fonts!


<l i nk r el =“ st yl esheet ” t ype=“ t ext / css”
hr ef =‘ ht t p: / / f ont s. googl eapi s. com css?
                                               /
f am l y=… >
     i      ’
And Tag Management




                     http://memegenerator.net/instance/27291297
HTTP Archive




               http://httparchive.org/trends.php
But I’d Notice…

 Globally?
 - Social sites tend to be targets for blocking
   - platform.twitter.com
   - connect.facebook.net
   - apis.google.com
 - HTTPS as well


 In an Enterprise?
 - Corporate policies
High Availability Server Architectures
  DNS
                                             Read-Only Database

              Load Balancers   App Servers




             Site 1



                                                                  Database Master



             Site 2
All for…

    Base Page
    (Back-end)
There are a LOT of requests!




                   http://httparchive.org/trends.php
http://memegenerator.net/instance/27291692



To the Front End!
Async Snippet
Good for code with no dependencies (widgets)


  <scr i pt >
    ( f unct i on( ) {
         var po = docum     ent . cr eat eEl ement ( ‘ scr i pt ’ ) ;
         po. sr c =
  ‘ ht t ps: / / api s. googl e. com j s/ pl usone. j s’ ;
                                     /
         var s = docum     ent . get El ement sByTagNam ‘ scr i pt ’ )
                                                           e(
  [ 0] ;
         s. par ent Node. i nser t Bef or e( po, s) ;
      })();
  </ scr i pt >
Simple Async Snippet
     Easy to implement and describe
     Slightly slower on IE than insertBefore()




<scr i pt sr c=‘ ht t ps: / / api s. googl e. com j s/ pl usone. j s’
                                                 /                      as ync
def er></ scr i pt >
Put Scripts at the Bottom
• Easy to implement and describe
• Delays script loading and execution later than Async at the top


      …
      <scr i pt
 sr c=‘ / / asset s. pi nt er est . com j s/ pi ni t . j s’ ></ scr i pt >
                                       /
 </ body>
Protocol-relative URLs
• Look strange
• Safe across all browsers (for Javascript)


 / / aj ax. googl eapi s. com aj ax/ l i bs/ j quer y/ 1. 6. 2/ j quer y. m n
                             /                                             i
 .js

 I nst ead of :

 ht t ps : / / aj ax. googl eapi s. com aj ax/ l i bs/ j quer y/ 1. 6. 2/ j que
                                       /
 r y. m n. j s
       i
Async Loaders
Help for dependency chaining

•   Modernizr
•   LABjs
•   RequireJS
•   ControlJS


     Modernizr.load([{
         load: '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js',
       }, {
         load: 'needs-jQuery.js'
     }]);
Modernizr.load([ {
    load: '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js',
    complete: function () {
      if ( !window.jQuery ) {
            Modernizr.load('js/libs/jquery-1.7.1.min.js');
      }
    }
  }, {
    load: 'needs-jQuery.js'
} ]);
WebFont Loader
 https://developers.google.com/webfonts/docs/webfont_loader


 Graceful fallback on failure
 Potential for unstyled content while loading
Well, Almost…


Desktop Browser           OnLoad Blocked               Mobile Browser           OnLoad Blocked
Chrome                    Yes                          Android 2.x              No
Firefox                   Yes                          Android 4.x+             Yes
Internet Explorer 9-      No                           Chrome Mobile            Yes
Internet Explorer 10      Yes                          iOS 4                    No
Safari 5+                 Yes                          iOS 5+                   Yes
Opera                     Yes                          IE Mobile 9              No



 http://www.browserscope.org/user/tests/table/agt1YS1wcm9maWxlcnINCxIEVGVzdBjrq90MDA
http://www.flickr.com/photos/phobia/2308371224/



How are we doing?
Widgets
 Async                  Blocking
 Google Analytics       Google +1 Badge
 Google +1 Button       Twitter Anywhere
 Twitter Tweet Button   Facebook Channel File Example
 Facebook Like Button   Pinterest (end of body)
 Digg                   Reditt
                        AddThis
                        ShareThis
Code Libraries (examples)

  • Closure Library: Blocking in the head
  • Dojo: Blocking in the head
  • Google jsapi: Blocking (default, Async available)
  • Jquery: Blocking in the head
  • Moo Tools: Blocking in the head
  • YUI: Blocking
Ad Providers

• Doubleclick: Fully Async available (October 2011)

• Adsense: Blocking script, ad itself is async

• Others: Ask – iFrame solutions are async
Fonts

  • Fontdeck: Blocking in the head
  • Fonts.com: Blocking in the head
  • Google: Blocking in the head
  • Typekit: Blocking in the head
  • Webtype: Blocking in the head


  • Loader works across all providers
Bonus Points



<script src=‘http://html5shim.googlecode.com/svn/trunk/html5.js’>

Minimal/No Caching
No gzip
No CDN
And wow, the trust!
http://memegenerator.net/instance/27291866
Routing to localhost

• Fails FAST! (connections rejected)
• Not good for real failure scenarios
You Need a Black Hole
blackhole.webpagetest.org – 72.66.115.13


hosts file
72.66.115.13 ajax.googleapis.com
72.66.115.13 apis.google.com
72.66.115.13 www.google-analytics.com
72.66.115.13 connect.facebook.net
72.66.115.13 platform.twitter.com
...




                                           Courtesy NASA/JPL-Caltech.
On WebPagetest.org




  ajax.googleapis.com
  apis.google.com
  www.google-analytics.com
  connect.facebook.net
  platform.twitter.com




                             http://www.webpagetest.org/
SPOF-O-Matic




       https://chrome.google.com/webstore/detail/plikhggfbplemddobondkeogomgoodeg



                                                                  https://github.com/pmeenan/spof-o-matic
http://memegenerator.net/instance/27293101

More Related Content

PPTX
Measuring web performance
PDF
Making the web faster
PDF
WebPagetest Power Users - Velocity 2014
PPTX
Measuring the visual experience of website performance
PPTX
Front-End Single Point of Failure - Velocity 2016 Training
PPT
Service Workers for Performance
PPT
Selecting and deploying automated optimization solutions
PDF
Velocity 2014 nyc WebPagetest private instances
Measuring web performance
Making the web faster
WebPagetest Power Users - Velocity 2014
Measuring the visual experience of website performance
Front-End Single Point of Failure - Velocity 2016 Training
Service Workers for Performance
Selecting and deploying automated optimization solutions
Velocity 2014 nyc WebPagetest private instances

What's hot (20)

PPT
Hands on performance testing and analysis with web pagetest
PDF
Tracking Performance - Velocity NYC 2013
PPTX
Web Performance Optimization
PPTX
Metrics, metrics everywhere (but where the heck do you start?)
PDF
Mobile web performance - MoDev East
PPTX
Getting the most out of WebPageTest
PDF
WebPagetest - Good, Bad & Ugly
PPTX
Using Modern Browser APIs to Improve the Performance of Your Web Applications
PDF
Forensic Tools for In-Depth Performance Investigations
PPTX
Automated Testing with Google Chrome - WebDriver- ChromeDriver
PPT
A web perf dashboard up & running in 90 minutes presentation
PPT
Scaling Front-End Performance - Velocity 2016
PPTX
Metrics, Metrics Everywhere (but where the heck do you start?)
PDF
Web performance testing with web driver
PPTX
Ruby in the Browser - RubyConf 2011
PPT
腾讯大讲堂09 如何建设高性能网站
PDF
Adventure Time with JavaScript & Single Page Applications
PDF
Web Page Test - Beyond the Basics
PDF
Are Today’s Good Practices… Tomorrow’s Performance Anti-Patterns?
PDF
Bringing the JAMstack to the Enterprise
Hands on performance testing and analysis with web pagetest
Tracking Performance - Velocity NYC 2013
Web Performance Optimization
Metrics, metrics everywhere (but where the heck do you start?)
Mobile web performance - MoDev East
Getting the most out of WebPageTest
WebPagetest - Good, Bad & Ugly
Using Modern Browser APIs to Improve the Performance of Your Web Applications
Forensic Tools for In-Depth Performance Investigations
Automated Testing with Google Chrome - WebDriver- ChromeDriver
A web perf dashboard up & running in 90 minutes presentation
Scaling Front-End Performance - Velocity 2016
Metrics, Metrics Everywhere (but where the heck do you start?)
Web performance testing with web driver
Ruby in the Browser - RubyConf 2011
腾讯大讲堂09 如何建设高性能网站
Adventure Time with JavaScript & Single Page Applications
Web Page Test - Beyond the Basics
Are Today’s Good Practices… Tomorrow’s Performance Anti-Patterns?
Bringing the JAMstack to the Enterprise
Ad

Viewers also liked (20)

PPTX
Machine Learning RUM - Velocity 2016
PPTX
TLS - 2016 Velocity Training
PPTX
Data viz as_interface_makoto_inoue
PDF
Velocity EU 2013 What is the velocity of an unladen swallow?
PPTX
Why Page Speed Isn't Enough - Tim Morrow - Velocity Europe 2012
PDF
Performance and Metrics at Lonely Planet
PDF
Are Today’s Good Practices… Tomorrow’s Performance Anti-Patterns?
PDF
Bring the Noise
PDF
MeasureWorks - Velocity Conference Europe 2012 - a Web Performance dashboard ...
PDF
Integrating multiple CDNs at Etsy
PDF
Getting 100B Metrics to Disk
PDF
Be Mean to Your Code with Gauntlt and the Rugged Way // Velocity EU 2013 Work...
PDF
Velocity EU 2012 Escalating Scenarios: Outage Handling Pitfalls
PDF
Monitoring and observability
PDF
Velocity 2013 london developer-friendly web performance testing in continuou...
PPTX
Velocity Europe 2013: Beyond Pretty Charts: Analytics for the cloud infrastru...
PDF
What HTTP/2.0 Will Do For You
PPTX
Step by Step Mobile Optimization
PPTX
Monitoring applicatif : Pourquoi et comment ?
PDF
Scaling Instagram
Machine Learning RUM - Velocity 2016
TLS - 2016 Velocity Training
Data viz as_interface_makoto_inoue
Velocity EU 2013 What is the velocity of an unladen swallow?
Why Page Speed Isn't Enough - Tim Morrow - Velocity Europe 2012
Performance and Metrics at Lonely Planet
Are Today’s Good Practices… Tomorrow’s Performance Anti-Patterns?
Bring the Noise
MeasureWorks - Velocity Conference Europe 2012 - a Web Performance dashboard ...
Integrating multiple CDNs at Etsy
Getting 100B Metrics to Disk
Be Mean to Your Code with Gauntlt and the Rugged Way // Velocity EU 2013 Work...
Velocity EU 2012 Escalating Scenarios: Outage Handling Pitfalls
Monitoring and observability
Velocity 2013 london developer-friendly web performance testing in continuou...
Velocity Europe 2013: Beyond Pretty Charts: Analytics for the cloud infrastru...
What HTTP/2.0 Will Do For You
Step by Step Mobile Optimization
Monitoring applicatif : Pourquoi et comment ?
Scaling Instagram
Ad

Similar to Velocity EU 2012 - Third party scripts and you (20)

PPTX
Google I/O 2012 - Protecting your user experience while integrating 3rd party...
PDF
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
PDF
Performance on the Yahoo! Homepage
KEY
Optimization of modern web applications
PDF
Building performance into the new yahoo homepage presentation
PPTX
Rohit&kunjan
PDF
Using React for the Mobile Web
KEY
HTML5와 모바일
KEY
Developing High Performance Web Apps - CodeMash 2011
PDF
The Mobile Web - HTML5 on mobile devices
KEY
Going on an HTTP Diet: Front-End Web Performance
PDF
Don't make me wait! or Building High-Performance Web Applications
PDF
WEB I - 01 - Introduction to Web Development
KEY
Html5 For Jjugccc2009fall
KEY
GWT - building a better web
PPTX
PDF
East of Toronto .NET Usergroup - Put the 5 in HTML
PDF
Tuning web performance
PDF
Tuning Web Performance
ODP
Web program-peformance-optimization
Google I/O 2012 - Protecting your user experience while integrating 3rd party...
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
Performance on the Yahoo! Homepage
Optimization of modern web applications
Building performance into the new yahoo homepage presentation
Rohit&kunjan
Using React for the Mobile Web
HTML5와 모바일
Developing High Performance Web Apps - CodeMash 2011
The Mobile Web - HTML5 on mobile devices
Going on an HTTP Diet: Front-End Web Performance
Don't make me wait! or Building High-Performance Web Applications
WEB I - 01 - Introduction to Web Development
Html5 For Jjugccc2009fall
GWT - building a better web
East of Toronto .NET Usergroup - Put the 5 in HTML
Tuning web performance
Tuning Web Performance
Web program-peformance-optimization

More from Patrick Meenan (11)

PPTX
Resource Prioritization
PPTX
HTTP/2 Prioritization
PDF
Http2 in practice
PPTX
Resource loading, prioritization, HTTP/2 - oh my!
PPTX
How fast is it?
PPTX
Service workers - Velocity 2016 Training
PPTX
Measuring performance - Velocity 2016 Training
PPTX
Image optimization
PDF
Velocity 2012 - Taming the Mobile Beast
PDF
Frontend SPOF
PPT
Web performance testing
Resource Prioritization
HTTP/2 Prioritization
Http2 in practice
Resource loading, prioritization, HTTP/2 - oh my!
How fast is it?
Service workers - Velocity 2016 Training
Measuring performance - Velocity 2016 Training
Image optimization
Velocity 2012 - Taming the Mobile Beast
Frontend SPOF
Web performance testing

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Electronic commerce courselecture one. Pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
NewMind AI Weekly Chronicles - August'25 Week I
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Dropbox Q2 2025 Financial Results & Investor Presentation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Electronic commerce courselecture one. Pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Network Security Unit 5.pdf for BCA BBA.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Mobile App Security Testing_ A Comprehensive Guide.pdf

Velocity EU 2012 - Third party scripts and you

  • 1. Third-Party Scripts and You Patrick Meenan pmeenan@webpagetest.org @patmeenan
  • 2. The Performance Golden Rule 80-90% of the end-user response time is spent on the frontend* www.flickr.com/photos/oreillyconf/6326167731/ * http://www.stevesouders.com/blog/2012/02/10/the-performance-golden-rule/
  • 3. Torbit Insight Real-User Data …1,000 sites representing 6.7 billion pageviews… …average 7% of load time is spent on the backend compared to a whopping 93% on the frontend. http://torbit.com/blog/2012/09/19/some-interesting-performance-statistics/
  • 4. Base Page Time to First Byte 4 Actual back-end Time!
  • 5. We can fix that! http://www.flickr.com/photos/elsie/4742380987/
  • 6. Social Widgets back-end API  Call directly from your back-end  Returns HTML to be injected directly into your page - echo file_get_contents(“http://social.patrickmeenan.com/gplus/?cookies=...”);  Implementation details: - Synchronous and blocking - Do not cache the results - If you need to set a timeout, make sure it is at least 20 seconds, 45 preferred - Include all cookies sent from the client - May return javascript and set cookies
  • 7. This Google guy is a complete nutter #velocityconf Wow, to think I used to respect @patmeenan #velocityconf
  • 8. But, that’s EXACTLY what this does… <scr i pt sr c=‘ … ’ ></ scr i pt > …
  • 11. When the widget is unavailable…
  • 13. Because of This: <scr i pt sr c=‘ ht t ps: / / api s. googl e. com j s/ pl usone. j s’ / ></ scr i p t> Instead of: <scr i pt > ( f unct i on( ) { var po = docum ent . cr eat eEl ement ( ‘ scr i pt ’ ); po. sr c = ‘ ht t ps: / / api s. googl e. com j s/ pl / usone. j s’ ; var s = docum ent . get El em ent sByTagNam ‘ e( scr i pt ’ ) [ 0] ; s. par ent Node. i nser t Bef or e( po, s) ; })(); </ scr i pt > Or Even: <scr i pt sr c=‘ ht t ps: / / api s. googl e. com j s/ pl usone. j s’ async / def er ></ scr i pt > http://www.stevesouders.com/blog/2009/12/01/google-analytics-goes-async/
  • 14. And Monitoring Says… • Server Monitoring Base page responded in 0.160 seconds • Full-Browser Monitoring Page loaded in 25 seconds • Analytics Page Views Loaded and executed asynchronously • Real User Monitoring Performance Reporting No data if user bailed before onLoad
  • 15. Loaded Asynchronously http://youtu.be/krin-F65Fd8
  • 16. Loaded Asynchronously http://youtu.be/krin-F65Fd8
  • 17. There’s More! On that one page, all before the main content: <scr i pt sr c=‘ ht t p: / / code. j quer y. com j quer y- / 1. 7. 1. mi n. j s’ ></ scr i pt > <scr i pt sr c=‘ ht t p: / / scr i pt s. ver t i cal acui t y. com vat / m / on/ vt . j s’ ></ scr i pt > <scr i pt sr c=‘ ht t p: / / ak. sai l - hor i zon. com scout / v1. j s’ ></ scr i pt > / <scr i pt sr c=‘ / / cdn. opt i m zel y. com j s/ xxxxx. j s’ ></ scr i pt > i / <scr i pt sr c=‘ ht t ps: / / pl at f or m t wi t t er . com anywher e. j s’ ></ scr i pt > . / <scr i pt sr c=‘ ht t p: / / www. r eddi t . com st at i c/ but t on/ but t on1. j s’ ></ scr i pt > / <scr i pt sr c=‘ ht t p: / / wi dget s. di gg. com but t ons. j s’ ></ scr i pt > /
  • 18. Watch out for Fonts! <l i nk r el =“ st yl esheet ” t ype=“ t ext / css” hr ef =‘ ht t p: / / f ont s. googl eapi s. com css? / f am l y=… > i ’
  • 19. And Tag Management http://memegenerator.net/instance/27291297
  • 20. HTTP Archive http://httparchive.org/trends.php
  • 21. But I’d Notice…  Globally? - Social sites tend to be targets for blocking - platform.twitter.com - connect.facebook.net - apis.google.com - HTTPS as well  In an Enterprise? - Corporate policies
  • 22. High Availability Server Architectures DNS Read-Only Database Load Balancers App Servers Site 1 Database Master Site 2
  • 23. All for… Base Page (Back-end)
  • 24. There are a LOT of requests! http://httparchive.org/trends.php
  • 26. Async Snippet Good for code with no dependencies (widgets) <scr i pt > ( f unct i on( ) { var po = docum ent . cr eat eEl ement ( ‘ scr i pt ’ ) ; po. sr c = ‘ ht t ps: / / api s. googl e. com j s/ pl usone. j s’ ; / var s = docum ent . get El ement sByTagNam ‘ scr i pt ’ ) e( [ 0] ; s. par ent Node. i nser t Bef or e( po, s) ; })(); </ scr i pt >
  • 27. Simple Async Snippet  Easy to implement and describe  Slightly slower on IE than insertBefore() <scr i pt sr c=‘ ht t ps: / / api s. googl e. com j s/ pl usone. j s’ / as ync def er></ scr i pt >
  • 28. Put Scripts at the Bottom • Easy to implement and describe • Delays script loading and execution later than Async at the top … <scr i pt sr c=‘ / / asset s. pi nt er est . com j s/ pi ni t . j s’ ></ scr i pt > / </ body>
  • 29. Protocol-relative URLs • Look strange • Safe across all browsers (for Javascript) / / aj ax. googl eapi s. com aj ax/ l i bs/ j quer y/ 1. 6. 2/ j quer y. m n / i .js I nst ead of : ht t ps : / / aj ax. googl eapi s. com aj ax/ l i bs/ j quer y/ 1. 6. 2/ j que / r y. m n. j s i
  • 30. Async Loaders Help for dependency chaining • Modernizr • LABjs • RequireJS • ControlJS Modernizr.load([{ load: '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js', }, { load: 'needs-jQuery.js' }]);
  • 31. Modernizr.load([ { load: '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js', complete: function () { if ( !window.jQuery ) { Modernizr.load('js/libs/jquery-1.7.1.min.js'); } } }, { load: 'needs-jQuery.js' } ]);
  • 32. WebFont Loader  https://developers.google.com/webfonts/docs/webfont_loader  Graceful fallback on failure  Potential for unstyled content while loading
  • 33. Well, Almost… Desktop Browser OnLoad Blocked Mobile Browser OnLoad Blocked Chrome Yes Android 2.x No Firefox Yes Android 4.x+ Yes Internet Explorer 9- No Chrome Mobile Yes Internet Explorer 10 Yes iOS 4 No Safari 5+ Yes iOS 5+ Yes Opera Yes IE Mobile 9 No http://www.browserscope.org/user/tests/table/agt1YS1wcm9maWxlcnINCxIEVGVzdBjrq90MDA
  • 35. Widgets Async Blocking Google Analytics Google +1 Badge Google +1 Button Twitter Anywhere Twitter Tweet Button Facebook Channel File Example Facebook Like Button Pinterest (end of body) Digg Reditt AddThis ShareThis
  • 36. Code Libraries (examples) • Closure Library: Blocking in the head • Dojo: Blocking in the head • Google jsapi: Blocking (default, Async available) • Jquery: Blocking in the head • Moo Tools: Blocking in the head • YUI: Blocking
  • 37. Ad Providers • Doubleclick: Fully Async available (October 2011) • Adsense: Blocking script, ad itself is async • Others: Ask – iFrame solutions are async
  • 38. Fonts • Fontdeck: Blocking in the head • Fonts.com: Blocking in the head • Google: Blocking in the head • Typekit: Blocking in the head • Webtype: Blocking in the head • Loader works across all providers
  • 41. Routing to localhost • Fails FAST! (connections rejected) • Not good for real failure scenarios
  • 42. You Need a Black Hole blackhole.webpagetest.org – 72.66.115.13 hosts file 72.66.115.13 ajax.googleapis.com 72.66.115.13 apis.google.com 72.66.115.13 www.google-analytics.com 72.66.115.13 connect.facebook.net 72.66.115.13 platform.twitter.com ... Courtesy NASA/JPL-Caltech.
  • 43. On WebPagetest.org ajax.googleapis.com apis.google.com www.google-analytics.com connect.facebook.net platform.twitter.com http://www.webpagetest.org/
  • 44. SPOF-O-Matic https://chrome.google.com/webstore/detail/plikhggfbplemddobondkeogomgoodeg https://github.com/pmeenan/spof-o-matic