SlideShare ist ein Scribd-Unternehmen logo
1 von 69
johnhrv@microsoft.com
Layout, Rende
            ring, Formattin
16%         g, …




      84%   JScript & DOM
Layout, Rende
            ring, Formattin
            g, …
33%


      67%
            JScript & DOM
CSS performance
Optimizing symbol resolution
Javascript coding inefficiencies
HTTP performance
table tr td ul li {color: green;}
li#pass {color: green;}



ul li {color: purple;}
ul > li {color: purple;}
Minimize included styles
Use less-complicated selectors
Don’t use expressions
Minimize page re-layouts
CSS Performance
Optimizing Symbol Resolution
JavaScript Coding Inefficiencies
HTTP Performance
Global                DOM

Intermediate          Prototype
     …         Cost      …

   Local              Instance
function WorkOnLocalVariable()
{
    localVariable = foo();
    return ( localVariable + 1 );
}
function WorkOnLocalVariable2()
{
    var localVariable = foo();
    return ( localVariable + 1 );
}
function BuildUI()
{
    var elm = document.getElementById('ui');

    // Clear existing contents
    elm.innerHTML = '';          7 innerHTML
                                  References
    // Generate UI
    elm.innerHTML += BuildTitle();
                   +=
    elm.innerHTML += BuildBody();
                   +=
    elm.innerHTML += BuildFooter();
                   +=
}
function BuildUI2()
{
    var elm = document.getElementById('ui');

    // Generate UI
                                    1 innerHTML
    var contents = BuildTitle()
                                     Reference
                 + BuildBody()
                 + BuildFooter();

    // Replace existing contents with UI
    elm.innerHTML = contents;
}
function CalculateSum()
{
    // Retrieve   Values
    var lSide =   document.body.all
                  document.body.all.lSide.value;
    var rSide =   document.body.all
                  document.body.all.rSide.value;

    // Generate Result
    document.body.all.result.value = lSide
    document.body.all
                                   + rSide;
}
function CalculateSum2()
{
    // Cache Element Collection
    var elms = document.body.all;

    // Retrieve   Values
    var lSide =   elms
                  elms.lSide.value;
    var rSide =   elms
                  elms.rSide.value;

    // Generate Result
    elms
    elms.result.value = lSide + rSide;
}
function IterateWorkOverCollection()
{
    var length = myCollection.length;

    for(var i = 0; i < length; i++)
    {
      Work
       Work(myCollection[i]);
    }
}
function IterateWorkOverCollection2()
{
    var funcWork = Work;
    var funcWork = Work;
    var length = myCollection.length;

    for(var i = 0; i < length; i++)
    {
      funcWork
       funcWork(myCollection[i]);
    }
}
http://channel9.msdn.com/pdc2008/TL24/
CSS Performance Considerations
Optimizing Symbol Resolution
JavaScript Coding Inefficiencies
HTTP Performance
http://wiki.ecmascript.org/doku.php?id=es3.1:json
_support
             http://www.json.org/json_parser.js
switch(option)
{
     case 1: …
     case 2: …
     case 3: …
     …
     case 1000: …
}
var lookup = {
      1: function(){…}
      2: function(){…}
      3: function(){…}
      …
      1000: function(){…}
}

try {
   lookup[option]();
  lookup [option]();
} catch(e) {
  // Default operation
}
var property = foo();

this.getProperty = function()
{
  return property;
}

this.setProperty = function(value)
{
  property = value;
}
this.property = foo();
Global                DOM

Intermediate          Prototype
     …         Cost      …

   Local              Instance
Global                DOM

Intermediate          Prototype
     …         Cost      …

   Local              Instance
Trident (MSHTML)

      DOM




 JScript Engine
function getElementsByClassName(className, node, tag) {
      …
      var elements = node.getElementsByTagName(tag);
      var elements = node.getElementsByTagName(tag);
      var pattern = new RegExp(quot;(^|s)quot; + className +
quot;(s|$)quot;);
                                elements.length
      for(var i = 0, j = 0; i < elements.length; i++) {
                             elements[i]
            if (pattern.test(elements[i].className)) {
                  classElements[j] = elements[i];
                    j++;
            }
      }
      return classElements;
}
function getElementsByClassName(className, node, tag)
{
      …
      var results = node.getElementsByTagName(tag);
      var elements = new Array(results.length);
      var elements = new Array(results.length);
      while (length--) elements[length] = results[length];
      while (length--) elements[length] = results[length];
      var pattern = new RegExp(quot;(^|s)quot; + className +
quot;(s|$)quot;);
      for(var i = 0, j = 0; i < elements.length i++) {
                                elements.length;
                             elements[i]
            if (pattern.test(elements[i].className)) {
                  classElements.push(results[i]);    j++;
  }
      } return classElements;
}
function LoopChildren(elm)
{
  var nodes = elm.childNodes;
  var length = nodes.length;

    for(var i = 0; i < length; i++)
    {
      var node = nodes[i];
                 nodes[i];
      …
    }
}
function LoopChildren2(elm)
{
  var node = elm.firstChild;

    while(node != null)
    {
      …
      node = node.nextSibling;
    }
}
function doValidation2()
{
   // Retrieve the required elements by using Selectors
   // Selects all form fields with 'required' classes
   var reqs = document.querySelectorAll
              document.querySelectorAll(quot;.requiredquot;);

    // Set the flag to false by default
    var missingRequiredField = false;

    // Validate that the form data is not empty
    for (var i = 0; i < reqs.length; i++) {
       if (reqs[i].value == quot;quot;)
         missingRequiredField = true;
    }
}
Use the native JSON object
Turn large switch statements into lookups
Avoid property access methods
Minimize DOM interaction
Use querySelectorAll for groups
CSS Performance
Optimizing Symbol Resolution
JavaScript Coding Inefficiencies
HTTP Performance
GET / HTTP/1.1                                   HTTP/1.1 200 OK
Accept: */*                                      Content-Length: 3479
Accept-Language: en-us                           Expires: -1
UA-CPU: x86                                      Date: Tue, 24 Apr 2007 21:30:46 GMT
Accept-Encoding: gzip, deflate                   Content-Type: text/html; charset=utf-8
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0)   Pragma: no-cache
Host: www.live.com                               Content-Encoding: gzip
                                                                    gzip
<html>
  <head>
     <title>Test</title>
  </head>
  <body>
     …
     <!-- icon.gif dimensions: 500 x 400 -->
     <img src=quot;icon.gifquot; width=quot;50quot; height=quot;40quot; />
     …
  </body>
</html>
<html>
  <head>
     <title>Test</title>
  </head>
  <body>
     …
     <!-- icon2.gif dimensions: 50 x 40 -->
     <img src=quot;icon2.gifquot; width=quot;50quot; height=quot;40quot; />
     …
  </body>
</html>
<html>
  <head>
     <title>Test</title>
     <script src=“1.js” … ></script>
     <script src= type=quot;text/javascriptquot;></script>
    <script src=“2.js” … ></script>
    <link href=“1.css” … ></link>
    <link href=“2.css” … ></link>
  </head>
  <body>
     …
  </body>
</html>
<html>
  <head>
     <title>Test</title>
     <script src=“1+2.js” … ></script>
     <script type=quot;text/javascriptquot;></script>
    <link href=“1+2.css” … ></link>

  </head>
  <body>
     …
  </body>
</html>
<html>
  <head>
     <title>Test</title>
  </head>
  <body>
     …
     <img src=quot;a.gifquot; />   Item 1
     <img src=quot;b.gifquot; />   Item 2
     …
  </body>
</html>
<head>
   <title>Test</title>
   <style type=quot;text/cssquot;>
       .a, .b { width: 10; height: 10 }
       .a, .b { background-image: quot;abc.gifquot; }
       .a { background-position: 0   0 }
       .b { background-position: 0 -10 }
       .b { background-position: 0 -10 }
   </style>
</head>
<body>
   …
   <div class=quot;aquot;></div> Item 1
   <div class=quot;aquot;></div>
   <div class=quot;bquot;></div>
   <div class=quot;bquot;></div> Item 2
   …
</body>
Request                              Response
GET /images/banner.jpg HTTP/1.1      HTTP/1.1 304 Not Modified
Host: www.microsoft.com              Content-Type: image/jpeg
If-Modified-Since:                   Last-Modified:
     Wed, 22 Feb 2006 04:15:54 GMT        Wed, 22 Feb 2006 04:15:54 GMT
Request                           Response
GET /images/banner.jpg HTTP/1.1   HTTP/1.1 200 OK
Host: www.microsoft.com           Content-Type: image/jpeg
                                  Expires: Fri, 12 Jun 2009 02:50:50 GMT




Request                           Response
GET /images/banner.jpg HTTP/1.1

                                             No response:
                                             Request serviced from
                                             cache
<html>
  <head>
     <title>Test</title>
     <script src=“1+2.js” … ></script>
     <script type=quot;text/javascriptquot;></script>
  </head>
  <body>
     …
  </body>
</html>
<html>
  <head>
     <title>Test</title>
  </head>
  <body>
     …
     <script src=“1+2.js” … ></script>
  </body>
</html>
www.fiddler2.com



http://www.fiddler2.com/fiddler2/addons/neXper
t.asp
Your feedback is important!
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market
                                                                                                 conditions,
          it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.
                                 MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Weitere ähnliche Inhalte

Was ist angesagt?

Symfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendSymfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friend
Kirill Chebunin
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf Conference
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 

Was ist angesagt? (20)

Symfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendSymfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friend
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Bottom Up
Bottom UpBottom Up
Bottom Up
 
Headless Js Testing
Headless Js TestingHeadless Js Testing
Headless Js Testing
 
this
thisthis
this
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
Introduction to Grails Framework
Introduction to Grails FrameworkIntroduction to Grails Framework
Introduction to Grails Framework
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern
 
Bubbles & Trees with jQuery
Bubbles & Trees with jQueryBubbles & Trees with jQuery
Bubbles & Trees with jQuery
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
Core concepts-javascript
Core concepts-javascriptCore concepts-javascript
Core concepts-javascript
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 

Ähnlich wie the next web now

Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web Performance
Adam Lu
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 

Ähnlich wie the next web now (20)

Building High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 FirestarterBuilding High Perf Web Apps - IE8 Firestarter
Building High Perf Web Apps - IE8 Firestarter
 
Performance patterns
Performance patternsPerformance patterns
Performance patterns
 
Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web Performance
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patterns
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
前端概述
前端概述前端概述
前端概述
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Rapid JCR Applications Development with Sling
Rapid JCR Applications Development with SlingRapid JCR Applications Development with Sling
Rapid JCR Applications Development with Sling
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

the next web now

  • 1.
  • 2.
  • 3.
  • 5.
  • 6.
  • 7. Layout, Rende ring, Formattin 16% g, … 84% JScript & DOM
  • 8. Layout, Rende ring, Formattin g, … 33% 67% JScript & DOM
  • 9.
  • 10. CSS performance Optimizing symbol resolution Javascript coding inefficiencies HTTP performance
  • 11.
  • 12.
  • 13. table tr td ul li {color: green;} li#pass {color: green;} ul li {color: purple;} ul > li {color: purple;}
  • 14.
  • 15.
  • 16.
  • 17. Minimize included styles Use less-complicated selectors Don’t use expressions Minimize page re-layouts
  • 18. CSS Performance Optimizing Symbol Resolution JavaScript Coding Inefficiencies HTTP Performance
  • 19. Global DOM Intermediate Prototype … Cost … Local Instance
  • 20. function WorkOnLocalVariable() { localVariable = foo(); return ( localVariable + 1 ); }
  • 21. function WorkOnLocalVariable2() { var localVariable = foo(); return ( localVariable + 1 ); }
  • 22. function BuildUI() { var elm = document.getElementById('ui'); // Clear existing contents elm.innerHTML = ''; 7 innerHTML References // Generate UI elm.innerHTML += BuildTitle(); += elm.innerHTML += BuildBody(); += elm.innerHTML += BuildFooter(); += }
  • 23. function BuildUI2() { var elm = document.getElementById('ui'); // Generate UI 1 innerHTML var contents = BuildTitle() Reference + BuildBody() + BuildFooter(); // Replace existing contents with UI elm.innerHTML = contents; }
  • 24. function CalculateSum() { // Retrieve Values var lSide = document.body.all document.body.all.lSide.value; var rSide = document.body.all document.body.all.rSide.value; // Generate Result document.body.all.result.value = lSide document.body.all + rSide; }
  • 25. function CalculateSum2() { // Cache Element Collection var elms = document.body.all; // Retrieve Values var lSide = elms elms.lSide.value; var rSide = elms elms.rSide.value; // Generate Result elms elms.result.value = lSide + rSide; }
  • 26. function IterateWorkOverCollection() { var length = myCollection.length; for(var i = 0; i < length; i++) { Work Work(myCollection[i]); } }
  • 27. function IterateWorkOverCollection2() { var funcWork = Work; var funcWork = Work; var length = myCollection.length; for(var i = 0; i < length; i++) { funcWork funcWork(myCollection[i]); } }
  • 28.
  • 29.
  • 30.
  • 32. CSS Performance Considerations Optimizing Symbol Resolution JavaScript Coding Inefficiencies HTTP Performance
  • 33.
  • 35.
  • 36. switch(option) { case 1: … case 2: … case 3: … … case 1000: … }
  • 37. var lookup = { 1: function(){…} 2: function(){…} 3: function(){…} … 1000: function(){…} } try { lookup[option](); lookup [option](); } catch(e) { // Default operation }
  • 38. var property = foo(); this.getProperty = function() { return property; } this.setProperty = function(value) { property = value; }
  • 40.
  • 41. Global DOM Intermediate Prototype … Cost … Local Instance
  • 42. Global DOM Intermediate Prototype … Cost … Local Instance
  • 43. Trident (MSHTML) DOM JScript Engine
  • 44. function getElementsByClassName(className, node, tag) { … var elements = node.getElementsByTagName(tag); var elements = node.getElementsByTagName(tag); var pattern = new RegExp(quot;(^|s)quot; + className + quot;(s|$)quot;); elements.length for(var i = 0, j = 0; i < elements.length; i++) { elements[i] if (pattern.test(elements[i].className)) { classElements[j] = elements[i]; j++; } } return classElements; }
  • 45. function getElementsByClassName(className, node, tag) { … var results = node.getElementsByTagName(tag); var elements = new Array(results.length); var elements = new Array(results.length); while (length--) elements[length] = results[length]; while (length--) elements[length] = results[length]; var pattern = new RegExp(quot;(^|s)quot; + className + quot;(s|$)quot;); for(var i = 0, j = 0; i < elements.length i++) { elements.length; elements[i] if (pattern.test(elements[i].className)) { classElements.push(results[i]); j++; } } return classElements; }
  • 46.
  • 47. function LoopChildren(elm) { var nodes = elm.childNodes; var length = nodes.length; for(var i = 0; i < length; i++) { var node = nodes[i]; nodes[i]; … } }
  • 48. function LoopChildren2(elm) { var node = elm.firstChild; while(node != null) { … node = node.nextSibling; } }
  • 49. function doValidation2() { // Retrieve the required elements by using Selectors // Selects all form fields with 'required' classes var reqs = document.querySelectorAll document.querySelectorAll(quot;.requiredquot;); // Set the flag to false by default var missingRequiredField = false; // Validate that the form data is not empty for (var i = 0; i < reqs.length; i++) { if (reqs[i].value == quot;quot;) missingRequiredField = true; } }
  • 50. Use the native JSON object Turn large switch statements into lookups Avoid property access methods Minimize DOM interaction Use querySelectorAll for groups
  • 51. CSS Performance Optimizing Symbol Resolution JavaScript Coding Inefficiencies HTTP Performance
  • 52.
  • 53. GET / HTTP/1.1 HTTP/1.1 200 OK Accept: */* Content-Length: 3479 Accept-Language: en-us Expires: -1 UA-CPU: x86 Date: Tue, 24 Apr 2007 21:30:46 GMT Accept-Encoding: gzip, deflate Content-Type: text/html; charset=utf-8 User-Agent: Mozilla/4.0 (compatible; MSIE 7.0) Pragma: no-cache Host: www.live.com Content-Encoding: gzip gzip
  • 54. <html> <head> <title>Test</title> </head> <body> … <!-- icon.gif dimensions: 500 x 400 --> <img src=quot;icon.gifquot; width=quot;50quot; height=quot;40quot; /> … </body> </html>
  • 55. <html> <head> <title>Test</title> </head> <body> … <!-- icon2.gif dimensions: 50 x 40 --> <img src=quot;icon2.gifquot; width=quot;50quot; height=quot;40quot; /> … </body> </html>
  • 56. <html> <head> <title>Test</title> <script src=“1.js” … ></script> <script src= type=quot;text/javascriptquot;></script> <script src=“2.js” … ></script> <link href=“1.css” … ></link> <link href=“2.css” … ></link> </head> <body> … </body> </html>
  • 57. <html> <head> <title>Test</title> <script src=“1+2.js” … ></script> <script type=quot;text/javascriptquot;></script> <link href=“1+2.css” … ></link> </head> <body> … </body> </html>
  • 58. <html> <head> <title>Test</title> </head> <body> … <img src=quot;a.gifquot; /> Item 1 <img src=quot;b.gifquot; /> Item 2 … </body> </html>
  • 59. <head> <title>Test</title> <style type=quot;text/cssquot;> .a, .b { width: 10; height: 10 } .a, .b { background-image: quot;abc.gifquot; } .a { background-position: 0 0 } .b { background-position: 0 -10 } .b { background-position: 0 -10 } </style> </head> <body> … <div class=quot;aquot;></div> Item 1 <div class=quot;aquot;></div> <div class=quot;bquot;></div> <div class=quot;bquot;></div> Item 2 … </body>
  • 60.
  • 61. Request Response GET /images/banner.jpg HTTP/1.1 HTTP/1.1 304 Not Modified Host: www.microsoft.com Content-Type: image/jpeg If-Modified-Since: Last-Modified: Wed, 22 Feb 2006 04:15:54 GMT Wed, 22 Feb 2006 04:15:54 GMT
  • 62. Request Response GET /images/banner.jpg HTTP/1.1 HTTP/1.1 200 OK Host: www.microsoft.com Content-Type: image/jpeg Expires: Fri, 12 Jun 2009 02:50:50 GMT Request Response GET /images/banner.jpg HTTP/1.1 No response: Request serviced from cache
  • 63. <html> <head> <title>Test</title> <script src=“1+2.js” … ></script> <script type=quot;text/javascriptquot;></script> </head> <body> … </body> </html>
  • 64. <html> <head> <title>Test</title> </head> <body> … <script src=“1+2.js” … ></script> </body> </html>
  • 66.
  • 67.
  • 68. Your feedback is important!
  • 69. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.