SlideShare a Scribd company logo
© 2006 Douglas Crockford
The Misconceived Web The original vision of the WWW was as a hyperlinked document-retrieval system. It did not anticipate presentation, session, or interactivity. If the WWW were still consistent with TBL's original vision, Yahoo would still be two guys in a trailer.
How We Got Here Rule Breaking Corporate Warfare Extreme Time Pressure
The Miracle It works! Java didn't. Nor did a lot of other stuff.
The Scripted Browser Introduced in Netscape Navigator 2 (1995) Eclipsed by Java Applets Later Became the Frontline of the Browser War Dynamic HTML Document Object Model (DOM)
Proprietary Traps Netscape and LiveWire Microsoft and Internet Information Services Both server strategies frustrated by Apache Browser-dependent sites
Pax Microsoft In the years since the end of the Browser War, the number of browser variations in significant use fell off significantly. W3C attempts to unify. Mozilla abandoned the Netscape  layer  model in favor of the W3C model. The browser platform becomes somewhat stable.  DHTML becomes known as Ajax.
Browser
Scripted Browser
The A List Firefox 1.5 Firefox 2.0 Safari 2 IE 6 IE 7 Opera 9 http://developer.yahoo.com/yui/articles/gbs/gbs_browser-chart.html
<script></script> <!--  // --> Hack for Mosaic and Navigator 1.0. language=javascript Deprecated. src= URL Highly recommended.  Don't put code on pages. type=text/javascript Ignored.
<script></script> Script files can have a big impact on page loading time. Place  <script src>  tags as close to the bottom of the body as possible. (Also, place CSS  <link>  as high in the head as possible.) Minify and gzip script files. Reduce the number of script files as much as possible.
document.write Allows JavaScript to produce HTML text. Before onload: Inserts HTML text into the document. After onload: Uses HTML text to replace the current document. Not recommended.
Collections document.anchors document.applets document.embeds document.forms document.frames document.images document.plugins document.scripts document.stylesheets Avoid these.
name   v  id name= Identifies values in form data Identifies a window/frame  id= Uniquely identifies an element They used to be interchangeable.
document.all Microsoft feature, rejected by W3C and most other browsers. It acts as a function or array for accessing elements by position,  name , or  id . Avoid it.
Retrieving Nodes document.getElementById( id ) document.getElementsByName( name ) node .getElementsByTagName( tagName )
Document Tree Structure document document.body document. documentElement
child , sibling, parent
child ,  sibling , parent
child ,  sibling ,  parent
child ,  sibling ,  parent
Walk the DOM Using recursion, follow the  firstChild  node, and then the  nextSibling  nodes. function walkTheDOM( node ,  func ) { func ( node );  node  =  node . firstChild ;  while ( node ) {  walkTheDOM( node ,  func );  node  =  node . nextSibling ;  }  }
getElementsByClassName function getElementsByClassName(className) {  var results = [];  walkTheDOM (document.body,  function (node) {  var a, c = node.className, i;  if (c) {  a = c.split(' ');  for (i = 0; i < a.length; i += 1) {  if (a[i] === className) {  results .push(node);  break;  }  }  }  } );  return results;  }
childNodes
Manipulating Elements IMG  has these properties: align 'none' ,  'top' ,  'left' , ... alt string border integer (pixels) height integer (pixels) hspace integer (pixels) id string isMap boolean src url useMap url vspace integer (pixels) width integer (pixels) node . property  =  expression ;
Manipulating Elements Old School if (my_image.complete) { my_image.src = superurl; } New School if (my_image.getAttribute('complete')) { my_image.setAttribute('src', superurl); }
Style node .className node .style. stylename node .currentStyle. stylename Only IE document.defaultView(). getComputedStyle( node , &quot;&quot;). getPropertyValue( stylename );
Style Names CSS background-color border-radius font-size list-style-type word-spacing z-index JavaScript backgroundColor borderRadius fontSize listStyleType wordSpacing zIndex
Making Elements document.createElement( tagName ) document.createTextNode( text ) node .cloneNode() Clone an individual element. node .cloneNode(true) Clone an element and all of its descendents. The new nodes are not connected to the document.
Linking Elements node .appendChild( new ) node .insertBefore( new ,  sibling ) node .replaceChild( new ,  old ) old.parentNode .replaceChild( new ,  old )
Removing Elements node .removeChild( old ) It returns the node.  Be sure to remove any event handlers. old.parentNode .removeChild( old )
innerHTML The W3C standard does not provide access to the HTML parser. All A browsers implement Microsoft's  innerHTML  property.
Which Way Is Better? It is better to build or clone elements and append them to the document? Or is it better to compile an HTML text and use innerHTML to realize it? Favor clean code and easy maintenance. Favor performance only in extreme cases.
Events The browser has an event-driven, single-threaded, asynchronous programming model. Events are targeted to particular nodes. Events cause the invocation of event handler functions.
Mouse Events The target is the topmost (z-index) node containing the cursor. click dblclick mousedown mousemove mouseout mouseover mouseup
Input Events The target is the node having focus. blur change focus keydown keypress keyup reset submit
Event Handlers Classic node [&quot;on&quot; +  type ] =  f ; Microsoft node .attachEvent(&quot;on&quot; +  type ,  f ); W3C node .addEventListener( type ,  f , false);
Event Handlers The handler takes an optional event parameter. Microsoft does not send an event parameter, use the global  event  object instead.
Event Handlers function (e) { e = e || event;  var target =  e.target || e.srcElement;   ... }
Trickling and Bubbling Trickling is an event capturing pattern which provides compatibility with the Netscape 4 model. Avoid it. Bubbling means that the event is given to the target, and then its parent, and then its parent, and so on until the event is canceled.
Why Bubble? Suppose you have 100 draggable objects. You could attach 100 sets of event handlers to those objects. Or you could attach one set of event handlers to the container of the 100 objects.
Cancel Bubbling Cancel bubbling to keep the parent nodes from seeing the event. e.cancelBubble = true; if (e.stopPropagation) { e.stopPropagation(); } Or you can use YUI's  cancelBubble  method.
Prevent Default Action An event handler can prevent a browser action associated with the event (such as submitting a form). e.returnValue = false; if (e.preventDefault) { e.preventDefault(); } return false; Or you can use YUI's  preventDefault  method.
Memory Leaks Memory management is automatic. It is possible to hang on to too much state, preventing it from being garbage collected.
Memory Leaks on IE 6 Explicitly remove all of your event handlers from nodes before you discard them. The IE6 DOM uses a reference counting garbage collector. Reference counting is not able to reclaim cyclical structures. You must break the cycles yourself.
Memory Leaks on IE 6 That was not an issue for page view-driven applications. It is a showstopper for Ajax applications.  It will be fixed in IE7.
Memory Leaks on IE 6 Remove all event handlers from deleted DOM nodes. It must be done on nodes before  removeChild  or  replaceChild . It must be done on nodes before they are replaced by changing  innerHTML .
Breaking Links in the DOM function purgeEventHandlers( node ) { walkTheDOM ( node ,  function (e) { for (var n in e) {  if (typeof e[n] ===  'function') { e[n] = null; } } } ); } Or you can use YUI's  purgeElement  method.
JavaScript alert( text ) confirm( text ) prompt( text ,  default ) These functions break the asynchronous model.  Avoid these in Ajax applications. setTimeout( func ,  msec ) setInterval( func ,  msec )
window The  window  object is also the JavaScript global object. Every window, frame, and iframe has its own unique  window  object. aka  self . And sometimes  parent  and  top .
Inter-window frames[] Child frames and iframes name Text name of window opener Reference to  open parent Reference to parent  self Reference to this window top Reference to outermost window Reference to this window open() Open new window
Inter-window A script can access another window if It can get a reference to it. document.domain === otherwindow.document.domain Same Origin Policy
Cross Browser Weak standards result in significant vendor-specific differences between browsers. Browser Detection. Feature Detection. Platform Libraries.
Browser Detection Determine what kind of browser that page is running in. Execute conditionally. The browsers lie.  navigator.userAgent Mozilla/4.0 Brittle. Not recommended. http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
Feature Detection Using reflection, ask if desired features are present. Execute conditionally. function addEventHandler(node, type, f) { if (node.addEventListener) { node.addEventListener(type, f, false);  } else if (node.attachEvent) {  node.attachEvent(&quot;on&quot; + type, f);  } else { node[&quot;on&quot; + type] = f; }  }
Feature Detection Using reflection, ask if desired features are present. Execute conditionally. function addEventHandler(node, type, f) { node[&quot;on&quot; + type] = f; } YAHOO.util.Event.addListener(node, type, f);  Support for custom events, and for adding events to object that don't exist yet, and for purging event handlers from objects.
Use a Platform Library A platform library insulates the application from the poisonous browsers. YUI is highly recommended. http://developer.yahoo.com/yui/
The Cracks of DOM The DOM buglist includes all of the bugs in the browser. The DOM buglist includes all of the bugs in all supported browsers. No DOM completely implements the standards. Much of the DOM is not described in any standard.
Coping Do what works. Do what is common. Do what is standard.
The Wall Browsers are now being push to their limits. Be prepared to back off. Reduce your memory requirements. Balance of client and server.
The Hole The browser was not designed to be a general purpose application platform. Lacks a compositing model. Accessibility suffers. Lacks support for cooperation under mutual suspicion.
The Peace is ending.
WWW War II Microsoft has awoken. They are beginning to innovate again. There are now 4 major browser makers. They will be flooding the web with bugs.
We Will Prevail We must use our clout to keep the browser makers in line. We must be players, not pawns. We must set the standards.
References The Document Object Model in Mozilla http://www.mozilla.org/docs/dom/ MSDN HTML and DHTML Reference http://msdn.microsoft.com/workshop/author/dhtml/ reference/dhtml_reference_entry.asp Introduction to Safari JavaScript Programming Topics http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSProgTopics/index.html Document Object Model (DOM) Level 2 Core Specification http://www.w3.org/TR/DOM-Level-2-Core/
Ad

More Related Content

What's hot (20)

How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
Ran Mizrahi
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
Aaron Gustafson
 
jQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsjQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation Labs
Prasad Shende
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
Bhavya Siddappa
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Jeado Ko
 
JavaOne TS-5098 Groovy SwingBuilder
JavaOne TS-5098 Groovy SwingBuilderJavaOne TS-5098 Groovy SwingBuilder
JavaOne TS-5098 Groovy SwingBuilder
Andres Almiray
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014
Jaroslaw Palka
 
Bootstrap과 UI-Bootstrap
Bootstrap과 UI-BootstrapBootstrap과 UI-Bootstrap
Bootstrap과 UI-Bootstrap
WebFrameworks
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
Robert Nyman
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
Subramanyan Murali
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Guillaume Laforge
 
React
React React
React
중운 박
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
cacois
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
FITC
 
Unit and functional testing with Siesta
Unit and functional testing with SiestaUnit and functional testing with Siesta
Unit and functional testing with Siesta
Grgur Grisogono
 
Mobile optimization
Mobile optimizationMobile optimization
Mobile optimization
purplecabbage
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
ygv2000
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
guileen
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
Remy Sharp
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats Bryntse
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
Ran Mizrahi
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
Aaron Gustafson
 
jQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation LabsjQuery with javascript training by Technnovation Labs
jQuery with javascript training by Technnovation Labs
Prasad Shende
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
Bhavya Siddappa
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Jeado Ko
 
JavaOne TS-5098 Groovy SwingBuilder
JavaOne TS-5098 Groovy SwingBuilderJavaOne TS-5098 Groovy SwingBuilder
JavaOne TS-5098 Groovy SwingBuilder
Andres Almiray
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014
Jaroslaw Palka
 
Bootstrap과 UI-Bootstrap
Bootstrap과 UI-BootstrapBootstrap과 UI-Bootstrap
Bootstrap과 UI-Bootstrap
WebFrameworks
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
Robert Nyman
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Guillaume Laforge
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
cacois
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
FITC
 
Unit and functional testing with Siesta
Unit and functional testing with SiestaUnit and functional testing with Siesta
Unit and functional testing with Siesta
Grgur Grisogono
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
ygv2000
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
guileen
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
Remy Sharp
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats Bryntse
 

Viewers also liked (14)

Douglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainDouglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your Brain
Web Directions
 
Performance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScriptPerformance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScript
jeresig
 
The JSON Saga
The JSON SagaThe JSON Saga
The JSON Saga
kaven yan
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
jeresig
 
Douglas Crockford - Ajax Security
Douglas Crockford - Ajax SecurityDouglas Crockford - Ajax Security
Douglas Crockford - Ajax Security
Web Directions
 
Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
jeresig
 
Json
JsonJson
Json
elliando dias
 
OOP in JavaScript
OOP in JavaScriptOOP in JavaScript
OOP in JavaScript
manugoel2003
 
Good Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas CrockfordGood Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas Crockford
rajivmordani
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Adieu
 
Advanced JavaScript Concepts
Advanced JavaScript ConceptsAdvanced JavaScript Concepts
Advanced JavaScript Concepts
Naresh Kumar
 
The DOM is a Mess @ Yahoo
The DOM is a Mess @ YahooThe DOM is a Mess @ Yahoo
The DOM is a Mess @ Yahoo
jeresig
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
guestceb98b
 
Speed Up Your JavaScript
Speed Up Your JavaScriptSpeed Up Your JavaScript
Speed Up Your JavaScript
Nicholas Zakas
 
Douglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainDouglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your Brain
Web Directions
 
Performance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScriptPerformance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScript
jeresig
 
The JSON Saga
The JSON SagaThe JSON Saga
The JSON Saga
kaven yan
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
jeresig
 
Douglas Crockford - Ajax Security
Douglas Crockford - Ajax SecurityDouglas Crockford - Ajax Security
Douglas Crockford - Ajax Security
Web Directions
 
Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
jeresig
 
Good Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas CrockfordGood Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas Crockford
rajivmordani
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Adieu
 
Advanced JavaScript Concepts
Advanced JavaScript ConceptsAdvanced JavaScript Concepts
Advanced JavaScript Concepts
Naresh Kumar
 
The DOM is a Mess @ Yahoo
The DOM is a Mess @ YahooThe DOM is a Mess @ Yahoo
The DOM is a Mess @ Yahoo
jeresig
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
guestceb98b
 
Speed Up Your JavaScript
Speed Up Your JavaScriptSpeed Up Your JavaScript
Speed Up Your JavaScript
Nicholas Zakas
 
Ad

Similar to The Theory Of The Dom (20)

Web Performance Tips
Web Performance TipsWeb Performance Tips
Web Performance Tips
Ravi Raj
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
Syed Irtaza Ali
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
Bert Wijnants
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Untangling8
Untangling8Untangling8
Untangling8
Derek Jacoby
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
David Padbury
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
Mike Wilcox
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
Perttu Myry
 
High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications 1197671494632682 2High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
Julien Lecomte
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Barry Gervin
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
Flavius-Radu Demian
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
Jonathan Fine
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
Dominic Arrojado
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
Christian Heilmann
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-Frameworks
Thomas Fuchs
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
Togakangaroo
 
Web Performance Tips
Web Performance TipsWeb Performance Tips
Web Performance Tips
Ravi Raj
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
Syed Irtaza Ali
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
Bert Wijnants
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
David Padbury
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
Mike Wilcox
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
Perttu Myry
 
High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications 1197671494632682 2High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications 1197671494632682 2
Niti Chotkaew
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
Julien Lecomte
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Barry Gervin
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
Jonathan Fine
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-Frameworks
Thomas Fuchs
 
Ad

More from kaven yan (9)

我的工作态度+@口碑网
我的工作态度+@口碑网我的工作态度+@口碑网
我的工作态度+@口碑网
kaven yan
 
我的工作态度@口碑网
我的工作态度@口碑网我的工作态度@口碑网
我的工作态度@口碑网
kaven yan
 
工作指南@口碑网
工作指南@口碑网工作指南@口碑网
工作指南@口碑网
kaven yan
 
HTML5@电子商务.com
HTML5@电子商务.comHTML5@电子商务.com
HTML5@电子商务.com
kaven yan
 
Http协议(rfc2616)中文版
Http协议(rfc2616)中文版Http协议(rfc2616)中文版
Http协议(rfc2616)中文版
kaven yan
 
互联网精神
互联网精神互联网精神
互联网精神
kaven yan
 
理解Ajax性能
理解Ajax性能理解Ajax性能
理解Ajax性能
kaven yan
 
拆分初始化负载
拆分初始化负载拆分初始化负载
拆分初始化负载
kaven yan
 
前端性能优化和自动化
前端性能优化和自动化前端性能优化和自动化
前端性能优化和自动化
kaven yan
 
我的工作态度+@口碑网
我的工作态度+@口碑网我的工作态度+@口碑网
我的工作态度+@口碑网
kaven yan
 
我的工作态度@口碑网
我的工作态度@口碑网我的工作态度@口碑网
我的工作态度@口碑网
kaven yan
 
工作指南@口碑网
工作指南@口碑网工作指南@口碑网
工作指南@口碑网
kaven yan
 
HTML5@电子商务.com
HTML5@电子商务.comHTML5@电子商务.com
HTML5@电子商务.com
kaven yan
 
Http协议(rfc2616)中文版
Http协议(rfc2616)中文版Http协议(rfc2616)中文版
Http协议(rfc2616)中文版
kaven yan
 
互联网精神
互联网精神互联网精神
互联网精神
kaven yan
 
理解Ajax性能
理解Ajax性能理解Ajax性能
理解Ajax性能
kaven yan
 
拆分初始化负载
拆分初始化负载拆分初始化负载
拆分初始化负载
kaven yan
 
前端性能优化和自动化
前端性能优化和自动化前端性能优化和自动化
前端性能优化和自动化
kaven yan
 

Recently uploaded (20)

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
 
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
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
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
 
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
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
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
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
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
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
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
 
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
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
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
 
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
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
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
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
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
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 

The Theory Of The Dom

  • 1. © 2006 Douglas Crockford
  • 2. The Misconceived Web The original vision of the WWW was as a hyperlinked document-retrieval system. It did not anticipate presentation, session, or interactivity. If the WWW were still consistent with TBL's original vision, Yahoo would still be two guys in a trailer.
  • 3. How We Got Here Rule Breaking Corporate Warfare Extreme Time Pressure
  • 4. The Miracle It works! Java didn't. Nor did a lot of other stuff.
  • 5. The Scripted Browser Introduced in Netscape Navigator 2 (1995) Eclipsed by Java Applets Later Became the Frontline of the Browser War Dynamic HTML Document Object Model (DOM)
  • 6. Proprietary Traps Netscape and LiveWire Microsoft and Internet Information Services Both server strategies frustrated by Apache Browser-dependent sites
  • 7. Pax Microsoft In the years since the end of the Browser War, the number of browser variations in significant use fell off significantly. W3C attempts to unify. Mozilla abandoned the Netscape layer model in favor of the W3C model. The browser platform becomes somewhat stable. DHTML becomes known as Ajax.
  • 10. The A List Firefox 1.5 Firefox 2.0 Safari 2 IE 6 IE 7 Opera 9 http://developer.yahoo.com/yui/articles/gbs/gbs_browser-chart.html
  • 11. <script></script> <!-- // --> Hack for Mosaic and Navigator 1.0. language=javascript Deprecated. src= URL Highly recommended. Don't put code on pages. type=text/javascript Ignored.
  • 12. <script></script> Script files can have a big impact on page loading time. Place <script src> tags as close to the bottom of the body as possible. (Also, place CSS <link> as high in the head as possible.) Minify and gzip script files. Reduce the number of script files as much as possible.
  • 13. document.write Allows JavaScript to produce HTML text. Before onload: Inserts HTML text into the document. After onload: Uses HTML text to replace the current document. Not recommended.
  • 14. Collections document.anchors document.applets document.embeds document.forms document.frames document.images document.plugins document.scripts document.stylesheets Avoid these.
  • 15. name v id name= Identifies values in form data Identifies a window/frame id= Uniquely identifies an element They used to be interchangeable.
  • 16. document.all Microsoft feature, rejected by W3C and most other browsers. It acts as a function or array for accessing elements by position, name , or id . Avoid it.
  • 17. Retrieving Nodes document.getElementById( id ) document.getElementsByName( name ) node .getElementsByTagName( tagName )
  • 18. Document Tree Structure document document.body document. documentElement
  • 20. child , sibling , parent
  • 21. child , sibling , parent
  • 22. child , sibling , parent
  • 23. Walk the DOM Using recursion, follow the firstChild node, and then the nextSibling nodes. function walkTheDOM( node , func ) { func ( node ); node = node . firstChild ; while ( node ) { walkTheDOM( node , func ); node = node . nextSibling ; } }
  • 24. getElementsByClassName function getElementsByClassName(className) { var results = []; walkTheDOM (document.body, function (node) { var a, c = node.className, i; if (c) { a = c.split(' '); for (i = 0; i < a.length; i += 1) { if (a[i] === className) { results .push(node); break; } } } } ); return results; }
  • 26. Manipulating Elements IMG has these properties: align 'none' , 'top' , 'left' , ... alt string border integer (pixels) height integer (pixels) hspace integer (pixels) id string isMap boolean src url useMap url vspace integer (pixels) width integer (pixels) node . property = expression ;
  • 27. Manipulating Elements Old School if (my_image.complete) { my_image.src = superurl; } New School if (my_image.getAttribute('complete')) { my_image.setAttribute('src', superurl); }
  • 28. Style node .className node .style. stylename node .currentStyle. stylename Only IE document.defaultView(). getComputedStyle( node , &quot;&quot;). getPropertyValue( stylename );
  • 29. Style Names CSS background-color border-radius font-size list-style-type word-spacing z-index JavaScript backgroundColor borderRadius fontSize listStyleType wordSpacing zIndex
  • 30. Making Elements document.createElement( tagName ) document.createTextNode( text ) node .cloneNode() Clone an individual element. node .cloneNode(true) Clone an element and all of its descendents. The new nodes are not connected to the document.
  • 31. Linking Elements node .appendChild( new ) node .insertBefore( new , sibling ) node .replaceChild( new , old ) old.parentNode .replaceChild( new , old )
  • 32. Removing Elements node .removeChild( old ) It returns the node. Be sure to remove any event handlers. old.parentNode .removeChild( old )
  • 33. innerHTML The W3C standard does not provide access to the HTML parser. All A browsers implement Microsoft's innerHTML property.
  • 34. Which Way Is Better? It is better to build or clone elements and append them to the document? Or is it better to compile an HTML text and use innerHTML to realize it? Favor clean code and easy maintenance. Favor performance only in extreme cases.
  • 35. Events The browser has an event-driven, single-threaded, asynchronous programming model. Events are targeted to particular nodes. Events cause the invocation of event handler functions.
  • 36. Mouse Events The target is the topmost (z-index) node containing the cursor. click dblclick mousedown mousemove mouseout mouseover mouseup
  • 37. Input Events The target is the node having focus. blur change focus keydown keypress keyup reset submit
  • 38. Event Handlers Classic node [&quot;on&quot; + type ] = f ; Microsoft node .attachEvent(&quot;on&quot; + type , f ); W3C node .addEventListener( type , f , false);
  • 39. Event Handlers The handler takes an optional event parameter. Microsoft does not send an event parameter, use the global event object instead.
  • 40. Event Handlers function (e) { e = e || event; var target = e.target || e.srcElement; ... }
  • 41. Trickling and Bubbling Trickling is an event capturing pattern which provides compatibility with the Netscape 4 model. Avoid it. Bubbling means that the event is given to the target, and then its parent, and then its parent, and so on until the event is canceled.
  • 42. Why Bubble? Suppose you have 100 draggable objects. You could attach 100 sets of event handlers to those objects. Or you could attach one set of event handlers to the container of the 100 objects.
  • 43. Cancel Bubbling Cancel bubbling to keep the parent nodes from seeing the event. e.cancelBubble = true; if (e.stopPropagation) { e.stopPropagation(); } Or you can use YUI's cancelBubble method.
  • 44. Prevent Default Action An event handler can prevent a browser action associated with the event (such as submitting a form). e.returnValue = false; if (e.preventDefault) { e.preventDefault(); } return false; Or you can use YUI's preventDefault method.
  • 45. Memory Leaks Memory management is automatic. It is possible to hang on to too much state, preventing it from being garbage collected.
  • 46. Memory Leaks on IE 6 Explicitly remove all of your event handlers from nodes before you discard them. The IE6 DOM uses a reference counting garbage collector. Reference counting is not able to reclaim cyclical structures. You must break the cycles yourself.
  • 47. Memory Leaks on IE 6 That was not an issue for page view-driven applications. It is a showstopper for Ajax applications. It will be fixed in IE7.
  • 48. Memory Leaks on IE 6 Remove all event handlers from deleted DOM nodes. It must be done on nodes before removeChild or replaceChild . It must be done on nodes before they are replaced by changing innerHTML .
  • 49. Breaking Links in the DOM function purgeEventHandlers( node ) { walkTheDOM ( node , function (e) { for (var n in e) { if (typeof e[n] === 'function') { e[n] = null; } } } ); } Or you can use YUI's purgeElement method.
  • 50. JavaScript alert( text ) confirm( text ) prompt( text , default ) These functions break the asynchronous model. Avoid these in Ajax applications. setTimeout( func , msec ) setInterval( func , msec )
  • 51. window The window object is also the JavaScript global object. Every window, frame, and iframe has its own unique window object. aka self . And sometimes parent and top .
  • 52. Inter-window frames[] Child frames and iframes name Text name of window opener Reference to open parent Reference to parent self Reference to this window top Reference to outermost window Reference to this window open() Open new window
  • 53. Inter-window A script can access another window if It can get a reference to it. document.domain === otherwindow.document.domain Same Origin Policy
  • 54. Cross Browser Weak standards result in significant vendor-specific differences between browsers. Browser Detection. Feature Detection. Platform Libraries.
  • 55. Browser Detection Determine what kind of browser that page is running in. Execute conditionally. The browsers lie. navigator.userAgent Mozilla/4.0 Brittle. Not recommended. http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
  • 56. Feature Detection Using reflection, ask if desired features are present. Execute conditionally. function addEventHandler(node, type, f) { if (node.addEventListener) { node.addEventListener(type, f, false); } else if (node.attachEvent) { node.attachEvent(&quot;on&quot; + type, f); } else { node[&quot;on&quot; + type] = f; } }
  • 57. Feature Detection Using reflection, ask if desired features are present. Execute conditionally. function addEventHandler(node, type, f) { node[&quot;on&quot; + type] = f; } YAHOO.util.Event.addListener(node, type, f); Support for custom events, and for adding events to object that don't exist yet, and for purging event handlers from objects.
  • 58. Use a Platform Library A platform library insulates the application from the poisonous browsers. YUI is highly recommended. http://developer.yahoo.com/yui/
  • 59. The Cracks of DOM The DOM buglist includes all of the bugs in the browser. The DOM buglist includes all of the bugs in all supported browsers. No DOM completely implements the standards. Much of the DOM is not described in any standard.
  • 60. Coping Do what works. Do what is common. Do what is standard.
  • 61. The Wall Browsers are now being push to their limits. Be prepared to back off. Reduce your memory requirements. Balance of client and server.
  • 62. The Hole The browser was not designed to be a general purpose application platform. Lacks a compositing model. Accessibility suffers. Lacks support for cooperation under mutual suspicion.
  • 63. The Peace is ending.
  • 64. WWW War II Microsoft has awoken. They are beginning to innovate again. There are now 4 major browser makers. They will be flooding the web with bugs.
  • 65. We Will Prevail We must use our clout to keep the browser makers in line. We must be players, not pawns. We must set the standards.
  • 66. References The Document Object Model in Mozilla http://www.mozilla.org/docs/dom/ MSDN HTML and DHTML Reference http://msdn.microsoft.com/workshop/author/dhtml/ reference/dhtml_reference_entry.asp Introduction to Safari JavaScript Programming Topics http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSProgTopics/index.html Document Object Model (DOM) Level 2 Core Specification http://www.w3.org/TR/DOM-Level-2-Core/