SlideShare a Scribd company logo
 
Building   Fast  3rd-Party  Webapps O'Reilly Velocity Web Performance and Operations Conference 24 June 2010 [email_address] [email_address] Lessons learned from the Meebo Bar Martin Hunt and Marcus Westin
The Meebo Bar A customizable site bar with real-time social interaction
Meebo Bar, a 3rd Party Webapp How do we make it run fast?   Loads on every page Interacts with the page JavaScript, CSS, Images & HTML How do we make it respectful? 
3rd Party Webapps The Challenge Do Load lots of features Load features fast Without Blocking rendering or onload Affecting User Experience How?
3rd Party Webapps: How? How to initialize a webapp Asynchronous & non-blocking   Defer Execution Minimize impact when loading CSS and Images Crush, Combine, Avoid  Perceived Performance Testing and psychology Tools Techniques
Meebo Bar embed code executes in ~10ms no blocking network requests no dependency on our server less than 1200 characters gzips to about 700 bytes embedded directly in page HTML or JS executes even if our servers are not reachable
Initializing 3rd Party Webapps Script Tag append a script tag using JavaScript to the head of the document Commonly accepted, but... Inline JS <script src=&quot;&quot;> easy for publishers to add blocks the page in all browsers XMLHttpRequests Asynchronous, non-blocking same-domain in most browsers Iframe <iframe src=&quot;&quot;> load an HTML file in an iframe Requires HTML file on the hosting site
Accepted script loading code var  head  =   document . getElementsByTagName ( 'head' )[ 0 ], el  =   document . createElement ( 'script' ); el. src   =   &quot;http://www.myDom.ain/myScript.js&quot; ; head. appendChild (el); good:  cross domain (we're 3rd party content!) good:  doesn't block network traffic
Don't block the page! Script Tag Append can block scripts in Firefox! blocks other scripts in Firefox scripts execute in order all scripts on the page block until the appended script downloads and executes (defer attribute supported in FF3.5+) blocks onload event in all browsers are there alternative nonblocking methods?
Iframed JS Iframes load HTML, not JS Cross iframe communication is same-domain only (non-HTML5 browsers) Window onload event fires  after  all iframes load
Iframed JS -  the solution      var  iframe  =   document . createElement ( 'iframe' ),          doc  =  iframe.contentWindow. document;      doc. open (). write ( '<body onload=&quot;appendScriptTag()&quot;>' )            doc. close ()
More About Iframes iframe creation overhead?      Creating one DOM node Chrome < 1ms Firefox, Safari ~1ms IE ~5ms Sandboxed JavaScript 3rd party code will not break webpage code Webpage code will not break 3rd party code! for (var i in x) {}
Defer Execution
Defer Execution Lots of stuff happens in a browser while loading a page     Then, relatively little happens... Take advantage of this!
Defer Execution Example In-page sharing  
Defer Execution Example In-page sharing  
Defer Execution Example In-page sharing  
Defer Execution Example In-page sharing
Naive implementation function makeSharable(elements) {      for (var i=0; i < elements.length; i++) {          var element = elements[i];          var metadata = lookupMetadata(element);          element.on('mousedown', startDrag, metadata);               } } function lookupMetadata(el) {      do {          inspectElement(el)      } while(el = el.parentNode) } O(N) O(M) O(N*M)
Deferred implementation function initShare() {      document.on('mousedown' , function(e) {          var el = e.target || e.srcElement          if (!el.getAttribute('meeboSharable')) { return; }          var metadata = lookupMetadata(el);          document.on('mousemove' , handleDrag, metadata);          document.on('mouseup',  stopDrag, metadata);      }); } O(1) Page finishes loading
Modularize & Lazy Load users don't need all features immediately 1-1 Messaging connect to all the IM networks Broadcasting publishers send new content to users Social Networking receive updates about your friends' activities Sharing share site content to Facebook, Twitter, Buzz, and other sites Site Widgets site-specific widgets: videos, menus, navigation tools, etc.
Modularize & Lazy Load Also applies to  images and CSS! Careful: Loading images can create  a lot of HTTP requests
Loading Images Spriting and preloading is  hard Still creates additional HTTP requests Difficult to automate Embed images into CSS instead DataURIs and MHTML files Details on the Meebo devblog (http://mee.bo/cssimages)
Use Vector Graphics Vector graphics are supported in all major browsers Firefox 3+ Opera 9.5+ IE 6+ Safari 3+ Chrome
  Without images With images
Tools -  use them! Preprocess if possible if multiple clients are doing the exact same task, run it on the server generate content offline Compilers Closure Compiler Profilers DynaTrace (IE) Speed tracer (Chrome) Firebug (FF) Safari 5/WebKit
Perceived Performance Quick loading content on a slow page appears to be the cause of the slow page Delaying interface drawing can look slow or broken Do not forget: Even asynchronous loading slows down a page.   Keep payloads minimal and always monitor performance!
Questions? [email_address] [email_address] Highlights Always compress and minify content Use an IFrame to load the main script payload Defer execution until needed Defer content download until needed Remove HTTP requests by combining content Embed images into CSS Use vector graphics
   

More Related Content

PDF
Meebo performance ny_web_performance
PPTX
That's crazy! how to build single page web apps
PDF
Web Development for UX Designers
PPTX
Fundamentals of HTML5
PPTX
Blazor - An Introduction
PPTX
Blazor Full-Stack
PPTX
Web Front End Performance
PDF
Web application intro
Meebo performance ny_web_performance
That's crazy! how to build single page web apps
Web Development for UX Designers
Fundamentals of HTML5
Blazor - An Introduction
Blazor Full-Stack
Web Front End Performance
Web application intro

What's hot (20)

PPTX
Use Powershell to make your life easy.
PDF
BP101: A Modernized Workflow w/ Domino/XPages
PDF
Technical SEO for WordPress - 2019 edition
PDF
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
PPTX
Web Components: Web back to future.
PDF
Progressive Enhancement
PPT
Introduction to Wordpress (Research Based)
PDF
Kickstarter Your Node.JS Application
PDF
12-2015-Meetup
PDF
Introducing asp.net web pages 2
PPT
Jquery
PDF
Build the mobile web you want
PDF
WP-CLI For The Win
PPTX
Performance Tuning Web Apps - The Need For Speed
ODP
Effective TDD - Less is more
PPTX
Wordpress Profitability for Agencies, Firms, and Freelancers
PDF
Harness the power of wordpress
PDF
Web dev syllabus
PDF
WordPress Security : What We Learnt When We Were Hacked : WordCamp Mumbai 2017
PPTX
Untangling spring week8
Use Powershell to make your life easy.
BP101: A Modernized Workflow w/ Domino/XPages
Technical SEO for WordPress - 2019 edition
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
Web Components: Web back to future.
Progressive Enhancement
Introduction to Wordpress (Research Based)
Kickstarter Your Node.JS Application
12-2015-Meetup
Introducing asp.net web pages 2
Jquery
Build the mobile web you want
WP-CLI For The Win
Performance Tuning Web Apps - The Need For Speed
Effective TDD - Less is more
Wordpress Profitability for Agencies, Firms, and Freelancers
Harness the power of wordpress
Web dev syllabus
WordPress Security : What We Learnt When We Were Hacked : WordCamp Mumbai 2017
Untangling spring week8
Ad

Viewers also liked (6)

PDF
Real World Haskell: Lecture 5
PDF
From Javascript To Haskell
PDF
Keynote ujihisa.vim#2
PDF
Real World Haskell: Lecture 6
PDF
Real World Haskell: Lecture 3
PDF
From Ruby to Haskell (Kansai Yami RubyKaigi)
Real World Haskell: Lecture 5
From Javascript To Haskell
Keynote ujihisa.vim#2
Real World Haskell: Lecture 6
Real World Haskell: Lecture 3
From Ruby to Haskell (Kansai Yami RubyKaigi)
Ad

Similar to Building fast webapps, fast - Velocity 2010 (20)

PPTX
JavaScript performance patterns
PDF
From nothing to a video under 2 seconds / Mikhail Sychev (YouTube)
KEY
Optimization of modern web applications
PPTX
JavaScript Performance Patterns
KEY
A rough guide to JavaScript Performance
PPTX
Web Directions South - Even Faster Web Sites
PDF
Performance on the Yahoo! Homepage
PDF
Building performance into the new yahoo homepage presentation
PPT
Sanjeev ghai 12
PPT
Oscon 20080724
PDF
Shifting Gears
PDF
PrairieDevCon 2014 - Web Doesn't Mean Slow
PPT
Fast Loading JavaScript
PDF
Understanding Page Load / Ziling Zhao (Google)
PPTX
Building Lightning Fast Websites (for Twin Cities .NET User Group)
PPT
High Performance Ajax Applications 1197671494632682 2
PPT
High Performance Ajax Applications
KEY
Developing High Performance Web Apps - CodeMash 2011
PDF
Js Saturday 2013 your jQuery could perform better
PPTX
Fronteers 20091105 (1)
JavaScript performance patterns
From nothing to a video under 2 seconds / Mikhail Sychev (YouTube)
Optimization of modern web applications
JavaScript Performance Patterns
A rough guide to JavaScript Performance
Web Directions South - Even Faster Web Sites
Performance on the Yahoo! Homepage
Building performance into the new yahoo homepage presentation
Sanjeev ghai 12
Oscon 20080724
Shifting Gears
PrairieDevCon 2014 - Web Doesn't Mean Slow
Fast Loading JavaScript
Understanding Page Load / Ziling Zhao (Google)
Building Lightning Fast Websites (for Twin Cities .NET User Group)
High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications
Developing High Performance Web Apps - CodeMash 2011
Js Saturday 2013 your jQuery could perform better
Fronteers 20091105 (1)

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
Teaching material agriculture food technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Cloud computing and distributed systems.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Approach and Philosophy of On baking technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
Teaching material agriculture food technology
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Understanding_Digital_Forensics_Presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Chapter 3 Spatial Domain Image Processing.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Review of recent advances in non-invasive hemoglobin estimation
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Cloud computing and distributed systems.
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Building fast webapps, fast - Velocity 2010

  • 1.  
  • 2. Building Fast  3rd-Party  Webapps O'Reilly Velocity Web Performance and Operations Conference 24 June 2010 [email_address] [email_address] Lessons learned from the Meebo Bar Martin Hunt and Marcus Westin
  • 3. The Meebo Bar A customizable site bar with real-time social interaction
  • 4. Meebo Bar, a 3rd Party Webapp How do we make it run fast?   Loads on every page Interacts with the page JavaScript, CSS, Images & HTML How do we make it respectful? 
  • 5. 3rd Party Webapps The Challenge Do Load lots of features Load features fast Without Blocking rendering or onload Affecting User Experience How?
  • 6. 3rd Party Webapps: How? How to initialize a webapp Asynchronous & non-blocking   Defer Execution Minimize impact when loading CSS and Images Crush, Combine, Avoid  Perceived Performance Testing and psychology Tools Techniques
  • 7. Meebo Bar embed code executes in ~10ms no blocking network requests no dependency on our server less than 1200 characters gzips to about 700 bytes embedded directly in page HTML or JS executes even if our servers are not reachable
  • 8. Initializing 3rd Party Webapps Script Tag append a script tag using JavaScript to the head of the document Commonly accepted, but... Inline JS <script src=&quot;&quot;> easy for publishers to add blocks the page in all browsers XMLHttpRequests Asynchronous, non-blocking same-domain in most browsers Iframe <iframe src=&quot;&quot;> load an HTML file in an iframe Requires HTML file on the hosting site
  • 9. Accepted script loading code var head = document . getElementsByTagName ( 'head' )[ 0 ], el = document . createElement ( 'script' ); el. src = &quot;http://www.myDom.ain/myScript.js&quot; ; head. appendChild (el); good:  cross domain (we're 3rd party content!) good:  doesn't block network traffic
  • 10. Don't block the page! Script Tag Append can block scripts in Firefox! blocks other scripts in Firefox scripts execute in order all scripts on the page block until the appended script downloads and executes (defer attribute supported in FF3.5+) blocks onload event in all browsers are there alternative nonblocking methods?
  • 11. Iframed JS Iframes load HTML, not JS Cross iframe communication is same-domain only (non-HTML5 browsers) Window onload event fires after all iframes load
  • 12. Iframed JS - the solution      var iframe = document . createElement ( 'iframe' ),          doc = iframe.contentWindow. document;      doc. open (). write ( '<body onload=&quot;appendScriptTag()&quot;>' )            doc. close ()
  • 13. More About Iframes iframe creation overhead?      Creating one DOM node Chrome < 1ms Firefox, Safari ~1ms IE ~5ms Sandboxed JavaScript 3rd party code will not break webpage code Webpage code will not break 3rd party code! for (var i in x) {}
  • 15. Defer Execution Lots of stuff happens in a browser while loading a page     Then, relatively little happens... Take advantage of this!
  • 16. Defer Execution Example In-page sharing  
  • 17. Defer Execution Example In-page sharing  
  • 18. Defer Execution Example In-page sharing  
  • 19. Defer Execution Example In-page sharing
  • 20. Naive implementation function makeSharable(elements) {      for (var i=0; i < elements.length; i++) {          var element = elements[i];          var metadata = lookupMetadata(element);          element.on('mousedown', startDrag, metadata);               } } function lookupMetadata(el) {      do {          inspectElement(el)      } while(el = el.parentNode) } O(N) O(M) O(N*M)
  • 21. Deferred implementation function initShare() {      document.on('mousedown' , function(e) {          var el = e.target || e.srcElement          if (!el.getAttribute('meeboSharable')) { return; }          var metadata = lookupMetadata(el);          document.on('mousemove' , handleDrag, metadata);          document.on('mouseup',  stopDrag, metadata);      }); } O(1) Page finishes loading
  • 22. Modularize & Lazy Load users don't need all features immediately 1-1 Messaging connect to all the IM networks Broadcasting publishers send new content to users Social Networking receive updates about your friends' activities Sharing share site content to Facebook, Twitter, Buzz, and other sites Site Widgets site-specific widgets: videos, menus, navigation tools, etc.
  • 23. Modularize & Lazy Load Also applies to  images and CSS! Careful: Loading images can create a lot of HTTP requests
  • 24. Loading Images Spriting and preloading is hard Still creates additional HTTP requests Difficult to automate Embed images into CSS instead DataURIs and MHTML files Details on the Meebo devblog (http://mee.bo/cssimages)
  • 25. Use Vector Graphics Vector graphics are supported in all major browsers Firefox 3+ Opera 9.5+ IE 6+ Safari 3+ Chrome
  • 26.   Without images With images
  • 27. Tools -  use them! Preprocess if possible if multiple clients are doing the exact same task, run it on the server generate content offline Compilers Closure Compiler Profilers DynaTrace (IE) Speed tracer (Chrome) Firebug (FF) Safari 5/WebKit
  • 28. Perceived Performance Quick loading content on a slow page appears to be the cause of the slow page Delaying interface drawing can look slow or broken Do not forget: Even asynchronous loading slows down a page.   Keep payloads minimal and always monitor performance!
  • 29. Questions? [email_address] [email_address] Highlights Always compress and minify content Use an IFrame to load the main script payload Defer execution until needed Defer content download until needed Remove HTTP requests by combining content Embed images into CSS Use vector graphics
  • 30.    

Editor's Notes

  • #3: MARCUS Martin &amp; Marcus We&apos;re here from Meebo commonly known as meebo.com today: Meebo is better known for the Meebo Bar
  • #4: MARCUS What is the Meebo Bar? Well, if you have a site, then you can add the Meebo Bar to your site and gain a number of features, such as social IM, sharing, ad revenue and more. The Meebo Bar launched almost 2 years ago. Since then we&apos;ve gone through 9 major iterations, and will soon be releasing Version 10. It will be the most technically advanced and best performing version of the bar as of yet. Since it&apos;s launch, the Meebo Bar has grown to more than 6000 websites and reaches more than 130 Million people every month The Meebo Bar lives inside of the hosting site. Because of its vast reach, it is crucial that the Meebo Bar does not slow down the site that it is on. If it does, than we slow down a significant portion of the web.
  • #5: MARCUS The Meebo Bar is a 3PWA. With 3PWA we mean javascript, css, images and HTML loaded onto a stie from a third party provider. 3PWAs commonly interact with the page, and often load on every page The question is then how do we make it run fast?  How do we make it respectful of its hosting environment?
  • #6: MARCUS More specifically, the challenge is to  Load lots of features Load those features fast Without Blocking rendering or onload and Without affecting the user experience in a negative way. How can we do that? Martin knows alot about how we can do that
  • #7: MARTIN You&apos;re already familiar with some tools - CDN - GZIP - PNG Crush We&apos;ll cover some tools &amp; techniques you&apos;re probably not familiar with Traditional 3rd Party Web App loading blocks - this is bad Defer code execution to not affect load time Optimize graphics and reduce image network requests Finally, we&apos;ll talk about deferring
  • #8: MARTIN Meebo Embed Code
  • #9: MARTIN Concerns Blocking page rendering Blocking network traffic Execute quickly and return control of the browser Only one piece of JS can run at a time! Should not depend on your servers
  • #10: MARTIN http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/
  • #11: MARTIN Concerns Blocking page rendering Blocking network traffic
  • #12: why might you not want to use an iframe? there are several problems that you might notice
  • #13: Out sample code for Loading asynchronous and nonblocking javascript same-domain iframe      with access to parent page      without blocking parent onload
  • #14: MARTIN iframe creation times are insignificant iframes guarantee sandboxing of your javascript
  • #16: MARCUS Lots of things happen in browser during load Parse, DOM, Layout, Render Then, realtively little happens As 3PWA developers we should take advantage of this! Let&apos;s look at an example
  • #17: MARCUS Any page with the Meebo Bar can have its videos, images and links made sharable by drag and drop. This means that when the page loads...
  • #18: MARCUS This means that when the page loads, the Meebo Bar scans the page for images, videos and links, and make them sharable When the user hovers...
  • #19: MARCUS When the user hovers over a sharable image, we display a drop shadow to indicate that this image is sharable by drag and drop On mouse down...
  • #20: MARCUS On mouse down, we display the Meebo Share UI, which allows the user to share the image to a number of social networks and any buddy in the buddy list. For each sharable item, Meebo infers the title, thumbnail and URL from the page. We allow for the site to specify these attributes on any parent node of a sharable element. Let&apos;s look at a naive implementation of this functionality
  • #21: MARCUS In this implementation, we loop over all elements that should be made sharable, look up the metadata for that element, and attach a mousedown event handler to that element lookupMetadata in turn climbs the DOM of the sharable element and inspects all parent nodes for metadata. Now, we want elements on the page to be made sharable right away, so we run this during page load.  A complex page can easily have tens of images and hundreds of links. Processing them all during loading of the page becomes noticable on all web browsers. Formally, the runtime of this approach is O(N * M), where N is the number of sharable elements and M is the number of ancestors of the sharable elements. Using the concept of deferred execution, we can do better.
  • #22: MARCUS The key to the concept of deferring is do as little as possible up front, and delay as much of the execution until as late as possible. In this example, we attach a single mousedown event handler to the entire document. Now, whenever the user does a mousedown, we check to see if the element the user moused down on is a sharable element. If it is, then go ahead and infer the metadata, and attach the remaining event handlers required for the drag and drop share UI This way we can go ahead and set up sharing right away during load without interfearing with the loading of the page. Formally, the runtime of this algorithm is constant on load, and linear when the user mouses down on a sharable elements. Both are unnoticable in all browsers.
  • #23: MARCUS That&apos;s a lot of code! And CSS and images! Break them down by features and load the code when the user needs it
  • #25: MARTIN
  • #26: MARTIN
  • #27: MARTIN SVG &amp; MHTML Meebo Bar   - Chrome   - Gradients   - Drop shadow   - No Images!
  • #28: MARTIN (overview slide)
  • #29: MARTIN We need better tools for measuring webapp performance!
  • #30: MARTIN