SlideShare a Scribd company logo
PERFOMANCE MATTERS
  DEVELOPING HIGH
 PERFORMANCE WEB
        APPS
       Timothy Fisher
        Compuware
     September 15, 2010
WHO AM I?

    Timothy Fisher
    Technical Consultant (Eagle)
    Compuware

        @tfisher
        tim.fisher@compuware.com
        www.timothyfisher.com
AGENDA

• Why   Front-end Performance Matters
• Optimize   Page Load
• Responsive   Interfaces
• Loading   and Executing JavaScript
AGENDA
• DOM     Scripting
• Tools

• Gomez    and Front-End Performance
• Questions


An overview to spark thought and further investigation
Why Front-end
Performance matters
According to Yahoo:
“80% of end-user response time is
spent on the front-end”

According to Steve Souders (Google performance guru):
“80-90% of end-user response
time is spent on the front-end”
Ads
                                     CDN’s




   Services
          Syndicated Content


Integration is happening on the client-side
OPTIMIZE PAGE LOAD
PAGE LOAD TIME
              IS IMPORTANT
Page load time is critical to the success of a web site/app
         Google: +500 ms → -20% traffic

         Yahoo: +400 ms → -5-9% full-page traffic

         Amazon: +100 ms → -1% sales

Small performance flucutations affect traffic and sales!!!
BEST PRACTICES

•   Minimize HTTP Requests
    •   combine javascript and css into less number of files

    •   consider sprites for combining images


•   Use a Content Delivery Network (CDN)
    •   static content delivered by fast distributed network with low latency
BEST PRACTICES

•   Make Pages Cacheable
    •   use appropriate header tags




•   Use GZIP Page Compression
    •   all modern browsers support GZIP compression
BEST PRACTICES

•   Place Stylesheets at the Top
    •   browser needs style info first to avoid repaints/reflows later




•   Place Scripts at the Bottom
    •   allow page content to be rendered first
BEST PRACTICES

•   Minify JavaScript and CSS
    •   save bandwidth / download time

    •   lots of tools to automate this for you




•   Post/pre Load Components
    •   consider how you are loading content and scripts
BEST PRACTICES

•   Split Components Across Domains
    •   enables browser to load more stuff in parallel




•   Optimize Images
    •   avoid high-res images unless it is intentional

    •   don’t let the browser scale your images
RESPONSIVE INTERFACES
A SINGLE BROWSER THREAD
SINGLE THREAD
                   IMPLICATIONS

• Single   UI Thread for both UI updates and JavaScript execution

  • only   one of these can happen at a time!


    Page downloading and rendering
    must stop and wait for scripts to be
    downloaded and executed
“0.1 second is about the limit for having the user feel
 that a system is reacting instantaneoulsy”
   - Jakob Nielsen, Usability Expert


Translation: No single JavaScript should execute for
more than 100 mS to ensure a responsive UI.
LOADING & EXECUTING
     JAVASCRIPT
WHY JAVASCRIPT?

•   Poorly written JavaScript is the most common reason
    for slow client-side performance

    • Loading

    • Parsing

    • Execution
TYPICAL JAVASCRIPT
             PLACEMENT
<html>
    <head>
        <link href=”style.css” rel=”stylesheet” type=”text/css”/>

        <script src=”myscript.js” type=”text/javascript”></script>
        <script src=”myscript.js” type=”text/javascript”></script>

        <script>
            function hello_world() {
                 alert(‘hello world’);
            }
            var complex_data = // some complex calculation //
        </script>
    </head>

    <body>
        ...
    </body>
</html>
BETTER JAVASCRIPT
            PLACEMENT
<html>
    <head>
        <link href=”style.css” rel=”stylesheet” type=”text/css”/>
    </head>

    <body>
        ...

        <script src=”myscript.js” type=”text/javascript”></script>
        <script src=”myscript.js” type=”text/javascript”></script>
        <script>
            function hello_world() {
               alert(‘hello world’);
            }
            var complex_data = // some complex calculation
        </script>
    </body>
</html>
COMBINE JAVASCRIPT FILES
•   Each script request requires HTTP performance overhead

•   Minimize overhead by combining scripts


                                                  file.js
             file1.js    file2.js   file3.js




                                            =>

                       Browser                   Browser
MINIFY JAVASCRIPT

• Removes     all unecessary space/comments from your JS files

• Replace   variables with short names

• Easy   to do at built-time with a tool

• Checkout YUI    Compressor, Closure Compiler...


 Avoid manual code-size optimization!
NON-BLOCKING LOADS

• AddJavaScript to a page in a way that does not block the
 browser thread

 ‣ Dynamic Script Elements
 ‣ Script Injection
DYNAMIC SCRIPT ELEMENTS


• JavaScript
          is downloaded and executed without blocking
 other page processes.

  var script = document.createElement(‘script’);
  script.type = “text/javascript”;
  script.src = “file1.js”;
  document.getElementsByTagName(“head”)[0].appendChild(script);
SCRIPT INJECTION
• Use Ajax to get script
• Can control when script is parsed/executed
• JavaScript must be served from same domain
    var xhr = XMLHttpRequest();
    xhr.open(“get”, “file.js”, true);
    xhr.onreadystatechange = function() {
       if (xhr.readyState == 4) {
         if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) {
           var script = document.createElement(“script”);
           script.type = “text/javascript”;
           script.text = xhr.responseText;
           document.body.appendChild(script);
         }
       }
    };
    xhr.send(null);
RECOMMENDED
       NONBLOCKING LOAD

• Includethe code necessary to dynamically the the rest of the
 JS required for page init

    <script type="text/javascript" src="loader.js"></script>
    <script type="text/javascript">
        loadScript("the-rest.js", function(){
            Application.init();
        });
    </script>




  Optionally include the loadScript function directly in the page
REAL WORLD USE

• This
     technique is used by many JavaScript libraries including
 YUI and Dojo.

   <script type="text/javascript"
    src="http://yui.yahooapis.com/combo?3.0.0/build/yui/yui-min.js"></script>



   YUI().use("dom", function(Y){
       Y.DOM.addClass(document.body, "loaded");
   });




   Dynamically loads the DOM utility and calls ‘loaded’ function
   when loading is complete.
SUMMARY

• Browser    UI and JS share a single thread

• Code  execution blocks other browser processes such as UI
 painting

• Put   script tags at the bottom of page

• Load   as much JS dynamically as possible

• Minimize   and compress your JS
DOM SCRIPTING
DOCUMENT OBJECT MODEL


 • Document Object Model (DOM) is a language
  independent API for working with HTML and XML


 • DOM  Scripting is expensive and a common cause of
  performance problems
DOM/JS ISOLATION

•   DOM and JavaScript implementations are independent
    of each other in all major browsers

•   This causes overhead performance costs as these two
    pieces of code must interface


            JavaScri
                                      DOM
               pt


      Minimize how many times you cross this bridge
BAD DOM SCRIPTING

Bad (we cross the bridge 1500 times!)
function innerHTMLLoop() {
    for (var count = 0; count < 1500; count++) {
        document.getElementById('here').innerHTML += 'a';
    }
}




Good (we cross the bridge 1 time)
function innerHTMLLoop2() {
    var content = '';
    for (var count = 0; count < 1500; count++) {
        content += 'a';
    }
    document.getElementById('here').innerHTML += content;
}
REPAINTS AND REFLOWS
  A reflow occurs whenever you change the
  geometry of an element that is displayed on the
  page.

  A repaint occurs whenever you change the
  content of an element that is displayed on the
  screen.

These are both expensive operations in terms of performance!
AVOIDING REPAINTS/REFLOWS
  This will potentially cause 3 repaints/reflows...
  var el = document.getElementById('mydiv');
  el.style.borderLeft = '1px';
  el.style.borderRight = '2px';
  el.style.padding = '5px';




  Better...    1 repaint/reflow
  var el = document.getElementById('mydiv');
  el.style.cssText = 'border-left: 1px; border-right: 2px; padding: 5px;';


  or...
  var el = document.getElementById('mydiv');
  el.className = 'active';
TOOLS
TOOLS ARE YOUR FRIEND
The right tools can help a developer identify and fix
performance problems related to client-side behaviour.

  Profiling
  Timing functions and operations during script
  execution

  Network Analysis
  Examine loading of images, stylesheets, and scripts
  and their effect on page load and rendering
FIREBUG
•Firefox plugin
•Debug JavaScript
•View page load waterfall:
PAGE SPEED
•Extension to Firebug from Google
•Provides tips for improving page performance
Y-SLOW

•Extension to Firebug from Yahoo
•tips for improving page performance
DYNATRACE AJAX EDITION

•extension for IE, coming soon for Firefox
•deeper client-side tracing than the firebug extensions
SPEED TRACER

•performance extension for Google Chrome
•similar features to Dynatrace Ajax
YUI PROFILER
•profile JavaScript performance
•developer must insert JS code
MORE TOOLS...

Internet Explorer Developer Tools

Safari Web Inspector

Chrome Developer Tools


Lots of developer tools to debug performance!
GOMEZ AND FRONT-END
   PERFORMANCE
GOMEZ

Gomez is the web performance division of Compuware

 •Active Monitoring
 synthetic tests using a dedicated node and a Gomez
 controlled browser

 •Actual Monitoring
 tests the actual end-user experience by transmitting
 data while users are browsing to a Gomez server
ACTIVE



ACTUAL
GOMEZ ACTIVE

• Synthetic tests
• Uses nodes in Gomez network to perform web
application testing.

• Today pure client-side metrics are not collected
GOMEZ ACTUAL

• Real User Monitoring (RUM)
• JavaScript ‘tags’ inserted into web pages.
• Tags report performance metrics to Gomez server
• Page and object load performance metrics
EXTENDING ACTIVE/ACTUAL
•Desire to collect more client-side metrics
 •JavaScript - load, parse, execution timing
 •CSS - load, parse timing
 •full Waterfall page load metrics
•Attribute client-side performance to specific sources
 (i.e. javascript library from vendor abc is the source of your slow performance)


•Expose full end-to-end performance
RESOURCES
•   Yahoo Exceptional Performance
    http://developer.yahoo.com/performance/

•   Google Web Performance
    http://code.google.com/speed

•   JavaScript: The Good Parts by Douglas Crockford

•   High Performance JavaScript by Nicholas Zakas

•   Even Faster Websites by Steve Souders

•   Steve Souders Site
    http://www.stevesouders.com

•   John Resig’s Blog
    http://www.ejohn.org
QUESTIONS
Ad

More Related Content

What's hot (20)

AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
Karl-Henry Martinsson
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
Jim Jeffers
 
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyS314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
Luciano Resende
 
Performance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinnessPerformance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinness
Stephen Thair
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
Bastian Hofmann
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5
dynamis
 
Seatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case StudySeatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case Study
Stephen Thair
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
AppUniverz Org
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
Simon Willison
 
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
Katy Slemon
 
London Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companiesLondon Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companies
Strangeloop
 
Web Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsWeb Page Test - Beyond the Basics
Web Page Test - Beyond the Basics
Andy Davies
 
Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5
Nathan Smith
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
Bruce Snyder
 
Beyond Breakpoints: Improving Performance for Responsive Sites
Beyond Breakpoints: Improving Performance for Responsive SitesBeyond Breakpoints: Improving Performance for Responsive Sites
Beyond Breakpoints: Improving Performance for Responsive Sites
Rakuten Group, Inc.
 
Web前端性能分析工具导引
Web前端性能分析工具导引Web前端性能分析工具导引
Web前端性能分析工具导引
冰 郭
 
soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5
soft-shake.ch
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
Peter Lubbers
 
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con InnomaticCostruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Innoteam Srl
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
Praveen kumar
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
Jim Jeffers
 
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyS314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
Luciano Resende
 
Performance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinnessPerformance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinness
Stephen Thair
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
Bastian Hofmann
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5
dynamis
 
Seatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case StudySeatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case Study
Stephen Thair
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
AppUniverz Org
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
Simon Willison
 
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
Katy Slemon
 
London Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companiesLondon Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companies
Strangeloop
 
Web Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsWeb Page Test - Beyond the Basics
Web Page Test - Beyond the Basics
Andy Davies
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
Bruce Snyder
 
Beyond Breakpoints: Improving Performance for Responsive Sites
Beyond Breakpoints: Improving Performance for Responsive SitesBeyond Breakpoints: Improving Performance for Responsive Sites
Beyond Breakpoints: Improving Performance for Responsive Sites
Rakuten Group, Inc.
 
Web前端性能分析工具导引
Web前端性能分析工具导引Web前端性能分析工具导引
Web前端性能分析工具导引
冰 郭
 
soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5
soft-shake.ch
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
Peter Lubbers
 
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con InnomaticCostruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Innoteam Srl
 

Similar to Developing High Performance Web Apps (20)

Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
Timothy Fisher
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
Gurpreet singh
 
Javascript & Jquery
Javascript & JqueryJavascript & Jquery
Javascript & Jquery
Gurpreet singh
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
Anup Hariharan Nair
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
Chris Love
 
Ui dev@naukri-2011
Ui dev@naukri-2011Ui dev@naukri-2011
Ui dev@naukri-2011
Pankaj Maheshwari
 
JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance Patterns
Stoyan Stefanov
 
Building performance into the new yahoo homepage presentation
Building performance into the new yahoo  homepage presentationBuilding performance into the new yahoo  homepage presentation
Building performance into the new yahoo homepage presentation
masudakram
 
Performance on the Yahoo! Homepage
Performance on the Yahoo! HomepagePerformance on the Yahoo! Homepage
Performance on the Yahoo! Homepage
Nicholas Zakas
 
7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites
oazabir
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
ssuser35fdf2
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
Ioan Eugen Stan
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patterns
Stoyan Stefanov
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
koppenolski
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
Morgan Cheng
 
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulationCS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)
Nicholas Zakas
 
Masterin Large Scale Java Script Applications
Masterin Large Scale Java Script ApplicationsMasterin Large Scale Java Script Applications
Masterin Large Scale Java Script Applications
Fabian Jakobs
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
Bob German
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
Mike Wilcox
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
Timothy Fisher
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
Gurpreet singh
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
Chris Love
 
JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance Patterns
Stoyan Stefanov
 
Building performance into the new yahoo homepage presentation
Building performance into the new yahoo  homepage presentationBuilding performance into the new yahoo  homepage presentation
Building performance into the new yahoo homepage presentation
masudakram
 
Performance on the Yahoo! Homepage
Performance on the Yahoo! HomepagePerformance on the Yahoo! Homepage
Performance on the Yahoo! Homepage
Nicholas Zakas
 
7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites
oazabir
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
ssuser35fdf2
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
Ioan Eugen Stan
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patterns
Stoyan Stefanov
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
koppenolski
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
Morgan Cheng
 
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulationCS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
CS8651- Unit 2 - JS.internet programming paper anna university -2017 regulation
amrashbhanuabdul
 
High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)High Performance JavaScript (Amazon DevCon 2011)
High Performance JavaScript (Amazon DevCon 2011)
Nicholas Zakas
 
Masterin Large Scale Java Script Applications
Masterin Large Scale Java Script ApplicationsMasterin Large Scale Java Script Applications
Masterin Large Scale Java Script Applications
Fabian Jakobs
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
Bob German
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
Mike Wilcox
 
Ad

Recently uploaded (20)

DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Ad

Developing High Performance Web Apps

  • 1. PERFOMANCE MATTERS DEVELOPING HIGH PERFORMANCE WEB APPS Timothy Fisher Compuware September 15, 2010
  • 2. WHO AM I? Timothy Fisher Technical Consultant (Eagle) Compuware @tfisher tim.fi[email protected] www.timothyfisher.com
  • 3. AGENDA • Why Front-end Performance Matters • Optimize Page Load • Responsive Interfaces • Loading and Executing JavaScript
  • 4. AGENDA • DOM Scripting • Tools • Gomez and Front-End Performance • Questions An overview to spark thought and further investigation
  • 6. According to Yahoo: “80% of end-user response time is spent on the front-end” According to Steve Souders (Google performance guru): “80-90% of end-user response time is spent on the front-end”
  • 7. Ads CDN’s Services Syndicated Content Integration is happening on the client-side
  • 9. PAGE LOAD TIME IS IMPORTANT Page load time is critical to the success of a web site/app Google: +500 ms → -20% traffic Yahoo: +400 ms → -5-9% full-page traffic Amazon: +100 ms → -1% sales Small performance flucutations affect traffic and sales!!!
  • 10. BEST PRACTICES • Minimize HTTP Requests • combine javascript and css into less number of files • consider sprites for combining images • Use a Content Delivery Network (CDN) • static content delivered by fast distributed network with low latency
  • 11. BEST PRACTICES • Make Pages Cacheable • use appropriate header tags • Use GZIP Page Compression • all modern browsers support GZIP compression
  • 12. BEST PRACTICES • Place Stylesheets at the Top • browser needs style info first to avoid repaints/reflows later • Place Scripts at the Bottom • allow page content to be rendered first
  • 13. BEST PRACTICES • Minify JavaScript and CSS • save bandwidth / download time • lots of tools to automate this for you • Post/pre Load Components • consider how you are loading content and scripts
  • 14. BEST PRACTICES • Split Components Across Domains • enables browser to load more stuff in parallel • Optimize Images • avoid high-res images unless it is intentional • don’t let the browser scale your images
  • 17. SINGLE THREAD IMPLICATIONS • Single UI Thread for both UI updates and JavaScript execution • only one of these can happen at a time! Page downloading and rendering must stop and wait for scripts to be downloaded and executed
  • 18. “0.1 second is about the limit for having the user feel that a system is reacting instantaneoulsy” - Jakob Nielsen, Usability Expert Translation: No single JavaScript should execute for more than 100 mS to ensure a responsive UI.
  • 19. LOADING & EXECUTING JAVASCRIPT
  • 20. WHY JAVASCRIPT? • Poorly written JavaScript is the most common reason for slow client-side performance • Loading • Parsing • Execution
  • 21. TYPICAL JAVASCRIPT PLACEMENT <html> <head> <link href=”style.css” rel=”stylesheet” type=”text/css”/> <script src=”myscript.js” type=”text/javascript”></script> <script src=”myscript.js” type=”text/javascript”></script> <script> function hello_world() { alert(‘hello world’); } var complex_data = // some complex calculation // </script> </head> <body> ... </body> </html>
  • 22. BETTER JAVASCRIPT PLACEMENT <html> <head> <link href=”style.css” rel=”stylesheet” type=”text/css”/> </head> <body> ... <script src=”myscript.js” type=”text/javascript”></script> <script src=”myscript.js” type=”text/javascript”></script> <script> function hello_world() { alert(‘hello world’); } var complex_data = // some complex calculation </script> </body> </html>
  • 23. COMBINE JAVASCRIPT FILES • Each script request requires HTTP performance overhead • Minimize overhead by combining scripts file.js file1.js file2.js file3.js => Browser Browser
  • 24. MINIFY JAVASCRIPT • Removes all unecessary space/comments from your JS files • Replace variables with short names • Easy to do at built-time with a tool • Checkout YUI Compressor, Closure Compiler... Avoid manual code-size optimization!
  • 25. NON-BLOCKING LOADS • AddJavaScript to a page in a way that does not block the browser thread ‣ Dynamic Script Elements ‣ Script Injection
  • 26. DYNAMIC SCRIPT ELEMENTS • JavaScript is downloaded and executed without blocking other page processes. var script = document.createElement(‘script’); script.type = “text/javascript”; script.src = “file1.js”; document.getElementsByTagName(“head”)[0].appendChild(script);
  • 27. SCRIPT INJECTION • Use Ajax to get script • Can control when script is parsed/executed • JavaScript must be served from same domain var xhr = XMLHttpRequest(); xhr.open(“get”, “file.js”, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) { var script = document.createElement(“script”); script.type = “text/javascript”; script.text = xhr.responseText; document.body.appendChild(script); } } }; xhr.send(null);
  • 28. RECOMMENDED NONBLOCKING LOAD • Includethe code necessary to dynamically the the rest of the JS required for page init <script type="text/javascript" src="loader.js"></script> <script type="text/javascript"> loadScript("the-rest.js", function(){ Application.init(); }); </script> Optionally include the loadScript function directly in the page
  • 29. REAL WORLD USE • This technique is used by many JavaScript libraries including YUI and Dojo. <script type="text/javascript" src="http://yui.yahooapis.com/combo?3.0.0/build/yui/yui-min.js"></script> YUI().use("dom", function(Y){ Y.DOM.addClass(document.body, "loaded"); }); Dynamically loads the DOM utility and calls ‘loaded’ function when loading is complete.
  • 30. SUMMARY • Browser UI and JS share a single thread • Code execution blocks other browser processes such as UI painting • Put script tags at the bottom of page • Load as much JS dynamically as possible • Minimize and compress your JS
  • 32. DOCUMENT OBJECT MODEL • Document Object Model (DOM) is a language independent API for working with HTML and XML • DOM Scripting is expensive and a common cause of performance problems
  • 33. DOM/JS ISOLATION • DOM and JavaScript implementations are independent of each other in all major browsers • This causes overhead performance costs as these two pieces of code must interface JavaScri DOM pt Minimize how many times you cross this bridge
  • 34. BAD DOM SCRIPTING Bad (we cross the bridge 1500 times!) function innerHTMLLoop() { for (var count = 0; count < 1500; count++) { document.getElementById('here').innerHTML += 'a'; } } Good (we cross the bridge 1 time) function innerHTMLLoop2() { var content = ''; for (var count = 0; count < 1500; count++) { content += 'a'; } document.getElementById('here').innerHTML += content; }
  • 35. REPAINTS AND REFLOWS A reflow occurs whenever you change the geometry of an element that is displayed on the page. A repaint occurs whenever you change the content of an element that is displayed on the screen. These are both expensive operations in terms of performance!
  • 36. AVOIDING REPAINTS/REFLOWS This will potentially cause 3 repaints/reflows... var el = document.getElementById('mydiv'); el.style.borderLeft = '1px'; el.style.borderRight = '2px'; el.style.padding = '5px'; Better... 1 repaint/reflow var el = document.getElementById('mydiv'); el.style.cssText = 'border-left: 1px; border-right: 2px; padding: 5px;'; or... var el = document.getElementById('mydiv'); el.className = 'active';
  • 37. TOOLS
  • 38. TOOLS ARE YOUR FRIEND The right tools can help a developer identify and fix performance problems related to client-side behaviour. Profiling Timing functions and operations during script execution Network Analysis Examine loading of images, stylesheets, and scripts and their effect on page load and rendering
  • 40. PAGE SPEED •Extension to Firebug from Google •Provides tips for improving page performance
  • 41. Y-SLOW •Extension to Firebug from Yahoo •tips for improving page performance
  • 42. DYNATRACE AJAX EDITION •extension for IE, coming soon for Firefox •deeper client-side tracing than the firebug extensions
  • 43. SPEED TRACER •performance extension for Google Chrome •similar features to Dynatrace Ajax
  • 44. YUI PROFILER •profile JavaScript performance •developer must insert JS code
  • 45. MORE TOOLS... Internet Explorer Developer Tools Safari Web Inspector Chrome Developer Tools Lots of developer tools to debug performance!
  • 46. GOMEZ AND FRONT-END PERFORMANCE
  • 47. GOMEZ Gomez is the web performance division of Compuware •Active Monitoring synthetic tests using a dedicated node and a Gomez controlled browser •Actual Monitoring tests the actual end-user experience by transmitting data while users are browsing to a Gomez server
  • 49. GOMEZ ACTIVE • Synthetic tests • Uses nodes in Gomez network to perform web application testing. • Today pure client-side metrics are not collected
  • 50. GOMEZ ACTUAL • Real User Monitoring (RUM) • JavaScript ‘tags’ inserted into web pages. • Tags report performance metrics to Gomez server • Page and object load performance metrics
  • 51. EXTENDING ACTIVE/ACTUAL •Desire to collect more client-side metrics •JavaScript - load, parse, execution timing •CSS - load, parse timing •full Waterfall page load metrics •Attribute client-side performance to specific sources (i.e. javascript library from vendor abc is the source of your slow performance) •Expose full end-to-end performance
  • 52. RESOURCES • Yahoo Exceptional Performance http://developer.yahoo.com/performance/ • Google Web Performance http://code.google.com/speed • JavaScript: The Good Parts by Douglas Crockford • High Performance JavaScript by Nicholas Zakas • Even Faster Websites by Steve Souders • Steve Souders Site http://www.stevesouders.com • John Resig’s Blog http://www.ejohn.org