For IE9 Platform Preview 4, we significantly re-architected how the Chakra JavaScript engine integrates into IE. This re-architecture, described in Dean’s post, subtly changes the programming model of the DOM for IE9 standards mode, making it consistent with new ECMAScript 5 capabilities, more interoperable with other browsers and aligned with emerging standards (WebIDL).
In this post I want to dive into the details of some of these programming model changes. You can take advantage of these enhanced DOM capabilities in the latest platform preview build. To highlight these changes, I’ll reference the Enhanced DOM Capabilities demo page that we released with the fourth Platform Preview.

That demo tests 24 capabilities that span 4 general categories:
The first two are closely related, so I’ll discuss them together:
DOM object inheritance from native JavaScript objects and JavaScript functional harmony with DOM objects.
Prior to IE9, the JavaScript engine was connected to the DOM via classic COM bindings. These legacy bindings allowed for only primitive object and function representations of the DOM to the JavaScript engine. Consequently, many basic JavaScript features that developers expected to be available to all objects and functions (including DOM objects like Window, Document, NodeList, etc.) were only available to native JavaScript objects (Array, Number, etc.).
The ECMAScript standard specifies basic operations that should work uniformly on all JavaScript objects, but allows “host objects” to deviate from those standard specifications. IE’s old JavaScript engine treated DOM objects as “host objects” which meant that basic JavaScript operations such as property access could behave oddly. While allowed by ECMAScript, inconsistent behavior between DOM objects and JavaScript objects created differences web developers had to account for.
For example, one common puzzler for many web developers was why IE DOM functions were reported as “object” to the typeof JavaScript operator rather than "function" (this capability is specifically checked in the demo as piece #10).
In IE9’s Standards Mode, we build our DOM as native JavaScript objects and functions rather than as “host objects,” thus enabling the features that web developers expect from native objects.
Interoperable programming features
The third group of capabilities showcase unique IE programming model behaviors that web developers commonly stumbled over. Because these behaviors were unique to the IE programming model, web developers found that their code didn't work the same across different browsers.
As part of our new integration architecture, we removed many of the inconsistencies that kept the same script from working the same way across browsers. The programming model changes may cause sites that have conditional code written for IE to behave differently in IE9 than it did before. Therefore, it is worthwhile describing these changes in more depth.
Functions now enumerated
In IE8 and before, enumerating a DOM object did not include any of that DOM object’s member functions. IE9 now enumerates any property on a DOM object that has its “enumerable” property descriptor value set to ‘true’. (In other words, enumeration can be programmatically altered.) Functions are now enumerated by default to be consistent with other browsers.
Removed implicit function invocation
DOM functions in previous versions of IE were quite special. Not only did they claim to be typeof “object”, but they also retained a static ‘this’ value which referred to the object to which they belonged. Consequently, it was possible to cache a reference to a DOM function, and invoke it without explicitly passing the ‘this’ value:
// Works in IE8 and earlier versions
// Doesn't work in IE9 or other browsers
var cachedGetElementById = document.getElementById;
cachedGetElementById('value');
In IE9, this now throws an exception, as it does in other browsers. Code that formerly depended on this IE behavior may use the “.call” workaround:
// Works in IE8/IE9 and other browsers
// Doesn't work in IE7 and earlier versions;
var cachedGetElementById = document.getElementById;
cachedGetElementById.call(document, 'value');
ECMAScript 5 provides a “bind” method for functions which allows them to take on the programming characteristics formerly supported by IE:
// Works natively in IE9 because of ECMAScript 5's 'bind' API
var cachedGetElementById = document.getElementById.bind(document);
cachedGetElementById('value');
Support for DOM exceptions and ‘const’ properties
The IE9 enhanced DOM now includes W3C-specified DOM exception objects and standardized error codes that web developers can use to determine (generally) the nature of a DOM API failure. These codes are commonly compared against well-defined 'const' properties to aid in code readability:
…
catch(ex) {
if (ex.code == DOMException.INDEX_SIZE_ERR)
…
}
The enhanced DOM provides the pre-defined 'const' properties as well as the architecture to throw and catch DOM exceptions.
Consistent toString behavior
With Chakra and the DOM fully integrated, the DOM does not have its own implementation of toString (a function that converts any object into a string form). While the old DOM’s toString implementation was similar to the JavaScript built-in version, it was not the same and often returned inconsistent or puzzling results. IE9 DOM objects now inherit and use the JavaScript built-in toString for more uniform results.
Separation of property and attribute storage
In the previous architecture, DOM objects had their own property storage. This property storage was the same as the storage location for attributes (those found in the HTML markup). With IE9's new architecture, an element’s attribute storage is now separate from the dynamic properties assigned to an element's script object. To illustrate this separation, consider the following example markup:
<div id="myId" class="c" user-defined-attribute="test">
In the above example, “id”, “class”, and “user-defined-attribute” are attributes. The div element's JavaScript object also exposes similar properties:
// Get the JavaScript object representing the body
var divOb = document.getElementById(‘myId’);
divOb.id; // "myId"
divOb.className; // "c"
These JavaScript properties retrieve the values stored in an element’s attribute list. For example, “id” retrieves the value of the “id” attribute. “className” retrieves the value of the “class” attribute.
In previous versions of IE, any dynamically-added properties would “magically” appear in the element’s attribute list and vice-versa due to the shared storage location. This could lead to unexpected results:
<div id="myId" class="c" user-defined-attribute="test">
…
var divOb = document.getElementById("myId");
// The next statement unexpectedly adds "userProperty" as
// an attribute to the element.
divOb.userProperty = "test"
// How many attributes?
alert("Total attributes = " + divOb.attributes.length);
IE9 and other browsers alert three total attributes ("id", "class", and "user-defined-attribute"), whereas previous versions of IE alert 4, adding "userProperty" to the list. The reverse example is more common—code that expects user-defined attributes to appear as dynamic properties:
<div id="myId" class="c" user-defined-attribute="test" userAttribute="test">
…
var divOb = document.getElementById("myId");
// Get the "userAttribute" and "user-defined-attribute" value
// (only worked in IE8 and previous versions)
var value1 = divOb.userAttribute;
var value2 = divOb["user-defined-attribute"];
We’ve seen a lot of code that expects this legacy IE behavior. The interoperable way to retrieve unknown attributes is to use “getAttribute,”
var value1 = divOb.getAttribute("userAttribute");
var value2 = divOb.getAttribute("user-defined-attribute");
and dynamic properties should not be queried through the attributes collection.
New ECMAScript 5 capabilities
In the last group of capability tests, new functionality provided by Chakra’s implementation of ECMAScript 5 is applied to the DOM. One of the primary goals for the enhanced DOM in IE9 was to provide a representation of the DOM that made logical sense within the context of the ECMAScript 5 language semantics. This was made much easier because one of the primary goals of ECMAScript 5 is to better support the functionality needed by DOM objects! In our implementation, we represented the DOM using as many native ECMAScript 5 language features as possible, including extensive use of accessor (getter/setter) properties.
This native integration allows all of the new ECMAScript5 features to work equally well with native objects as with DOM objects.
The enhanced DOM capabilities demo shows only 24 samples of what is possible when the DOM is fully integrated with an ECMAScript 5-capable JavaScript engine like Chakra. We are very excited about this support in IE9 and want to help get better interoperability for ECMAScript language bindings across browsers. An important step is standardizing these binding within the W3C, and we’re happy to contribute to that effort.
W3C web standards have always supplied a language binding for ECMAScript implementations as a way to translate the standard IDL (Interface Definition Language) into JavaScript objects. However, these bindings lacked sufficient detail to create much more than a simple “host object” binding (a binding without consideration of the full spectrum of ECMAScript language features). While other browsers have a much more comprehensive language binding than simply “host objects,” integration inconsistencies remain. These inconsistencies can really frustrate JavaScript framework developers who wish to write abstraction layers and features on top of the basic language support. The need for consistency led to a proposed standard called WebIDL (Web Interface Definition Language). The WebIDL specification describes in much more precise detail, how to translate a given W3C spec written using WebIDL into JavaScript objects.
In a follow-up post, I will describe in more detail how we used WebIDL to inform and guide the development of the IE9 enhanced DOM.
Please testdrive the IE9 enhanced DOM. We look forward to your comments and feedback.
Travis Leithead
IE Program Manager
For those of you that don’t subscribe to the YUI calendar or YUILibrary.com forum, the next installment of YUI: Open Hours will be this Friday the 3rd.
The topic of this week’s call will be performance. How and what to measure in your module code, and techniques and tools for measuring various aspects of site performance.
On deck this week are Ryan Grove, Satyen Desai, and Philip Tellis. Satyen will be demoing dynaTrace Ajax edition, Philip will be introducing a new YSlow plugin he’s working on, and Ryan will cover some of the tools in YUI 3 that you can use in your development to move the needle.
So bring your slow or ailing code (or fast code if you want to show off) and participate in the conversation.
As usual, we’ll be online from 10am to 12pm PDT. The connection details are the same as usual.
Here’s the forum thread for this Open Hours. I’ll post some of the interesting takeaways after the call and we’ll be recording the call for those that can’t make it for the entire time.
Follow @yuilibrary on Twitter for the latest updates on Open Hours and other YUI interestingness.
Hope to see you there!
* – If Skype is not an option, email me for a local number.
This is a guest post by Owen Barton, partner and director of engineering at CivicActions. Owen has been working with Google's “Make the Web Faster” project team and the Drupal community to make improvements in Drupal 7 front-end performance. This is a condensed version of a more in-depth post over at the CivicActions blog.
Drupal is a popular free and open source publishing platform, powering high profile sites such as The White House, The New York Observer and Amnesty International. The Drupal community has long understood the importance of good front-end performance to successful web sites, being ahead of the game in many ways. This post highlights some of the improvements developed for the upcoming Drupal 7 release, several of which can save an additional second or more of page load times.
Drupal 7 has made its caching system more easily pluggable - to allow for easier memcache integration, for example. It has also enabled caching HTTP headers to be set so that logged out users can cache entire pages locally as well as improve compatibility with reverse proxies and content distribution networks (CDNs). There is also a patch waiting which reduces both the response size and the time taken to generate 404 responses for inlined page assets. Depending on the type of 404 (CSS have a larger effect than images, for example) the slower 404s were adding 0.5 to 1 second to the calling page load times.
Drupal currently has the ability to aggregate multiple CSS and JavaScript files by concatenating them into a smaller number of files to reduce the number of HTTP requests. There is a patch in the queue for Drupal 7 that could allow aggregation to be enabled by default, which is great because the large number of individual files can add anything from 0-1.5 seconds to page loads.
One issue that has become apparent with the Drupal 6 aggregation system is that users can end up downloading aggregate files that include a large amount of duplicate code. On one page the aggregate may contain files a, b and c, whilst on a second page the aggregate may contain files a, b and d - the “c” and “d” files being added conditionally on specific pages. This breaks the benefits of browser caching and slows down subsequent page loads. Benchmarking on core alone shows that avoiding duplicate aggregates can save over a second across 5 page loads. A patch has already been committed that means files need to be explicitly added to the aggregate, and fix Drupal core to add appropriate files to the aggregate unconditionally.
Drupal has supported gzip compression of HTML output for a long time, however for CSS and JavaScript, the files are delivered directly by the webserver, so Drupal has less control. There are webserver based compressors such as Apache’s mod_deflate, but these are not always available. A patch is in the queue that stores compressed versions of aggregated files on write and uses rewrite and header directives in .htaccess that allow these files to be served correctly. Benchmarks show that this patch can make initial page views 20-60% faster, saving anything from 0.3 to 3 seconds total.
The Drupal 7 release promises some real improvements from a front-end performance point of view. Other performance optimizations will no doubt continue to appear and be refined in contributed modules and themes, as well as in site building best practices and documentation. In Drupal 8 we will hopefully see further improvements in the CSS/JS file aggregation system, increased high-level caching effectiveness and hopefully more tools to help site builders reduce file sizes. If you have yet to try Drupal, download it now and give it a try and tell us in the comments if your site performance improves!
by Mike Krumboltz
Online videos go viral all the time. But rare is the case that an unintentionally funny clip can lead to a paying gig. That's exactly what's happened to Paul "Bear" Vasquez, better known as "Double Rainbow Guy."
Anyone who spends more than five minutes online per day probably remembers Mr. Vasquez's video, in which he captured footage of the elusive double rainbow outside his home near Yosemite. While the video of the double rainbow is impressive, it's Mr. Vasquez's commentary — in which he laughs, weeps, and questions the cosmos — that made the clip a classic.
Somebody at Microsoft was apparently a fan, because the company hired the rainbow-worshiping maniac to star in a commercial. In the ad, Vasquez takes photos of a double rainbow (of course) and then edits them together using Windows Live photo editing software, while mumbling some of his best-known lines.
An official blog from Windows explains how the Seattle company contacted Vasquez and explained their ideas for the ad. Not surprisingly, Vasquez was "ecstatic" at the idea of doing a "Double Rainbow Redux." So, he flew to Seattle, they shot the video, and celebrated with a feast of Vietnamese food (the star's favorite).
The commercial is a nice clip, but in our humble opinion, it can't match the original. It's just ... so intense!
The advertisement ...
And an interview that includes clips from the original ...
by Claudine Zap
In the movie "Machete," Danny Trejo stars as a tough-guy gun for hire. In real life, the character actor started out as an actual criminal who did hard time in San Quentin.
The cartoonishly violent romp of a movie stars Trejo as a former cop from Mexico turned vengeful vigalante out for blood. He'll go after bad cops, bad politicans, and bad drug dealers. The movie features over-the-top mayhem that includes "beheadings, skewerings and kill shots to the head by the dozen." It also features some serious star power: Robert De Niro, Steven Seagal, Don Johnson, Michelle Rodriguez, and Jessica Alba.
If you've never heard of Danny Trejo, trust us, you've seen him. The L.A.-born actor has had a prolific career -- including a stint as the star of the fake trailer for "Machete" in the campy movie "Grindhouse" four years ago. But you can catch him in many action flicks, from "Con Air" to "Predators" to "Spy Kids."
The spoof "Machete" trailer led to the full-length movie with Trejo at the lead. This would not seem the obvious path for a drug-addicted kid in and out of jail for 11 years. Sent to San Quentin for drug offenses and armed robbery, Trejo turned to boxing and a 12-step program, which began his turnaround.
And here is where the story goes Hollywood: Once on the outside, Trejo spoke at a 12-step meeting, and a young man called him for support. Trejo met him on the set of "Runaway Train." A fellow ex-convict recognized him, and offered him a gig training one of the stars, Eric Roberts. When he did so well with that, the director offered him a feature role in the movie. And Trejo was on his way.
The tattooed Mexican-American landed a role in "Desperado," and has served as a muse for director Robert Rodriguez ever since, appearing in 8 of his movies and leading him to the starring role of "Machete."
Though Trejo's star is soaring, one of his fellow "Machete" actors -- who has also had real-life troubles -- should be happy to have a bit part: Lindsay Lohan.
See a video short of Trejo returning to his childhood neighborhood in East Los Angeles as a conquering hero.
by Mike Krumboltz
Hurricane Earl has been brewing over the Atlantic Ocean for several days, and is now swirling toward America's East Coast. People who fear they may be in harm's way are going online for the latest on the storm's path and destructive power.
Over the past 24 hours, online lookups for "hurricane earl path" have more than doubled. Related queries on "hurricane earl tracker" and "hurricane earl pictures" have also soared.
The Category 3 hurricane, which is as large as the state of California, is projected to approach North Carolina's Outer Banks on Thursday night, according to the National Hurricane Center. Gov. Bev Purdue was quoted as saying, "We're very ready, as ready as anybody can be." By Friday night, experts predict it will hit parts of southeastern New England.
In North Carolina, where Earl poses a particular danger, searches are especially high. Lookups on "hurricane earl 2010 track" are up 146% and "hurricane earl path" surged 64%, placing the term among the state's top 75 overall lookups. There is also massive Web interest in "hurricane earl wind speeds." According to CNN, the sustained wind is around 125 mph, with gusts up to 165 mph.
While there is tremendous search interest in things like "hurricane kits" and "storm shutters," people are most interested in tracking the hurricane. A buzzy article from the AP explains that predicting a hurricane's path is getting easier to do, thanks to high-tech computers.
You can follow Earl via The Weather Channel's easy-to-read map. The National Weather Service, a government-run site, includes a "5-day forecast cone" and coastal watches.
