Tales from the Evil Empire

Bertrand Le Roy's blog

News

Ads Via DevMavens

ASP.NET AJAX UpdatePanel Control: Add Ajax interactivity to your ASP.NET 2.0 web pages


follow bleroy at http://twitter.com

Bertrand Le Roy




Add to Technorati Favorites

Blogs I read

My other stuff

Let me explain one more time why the Atlas compatibility layer works this way...

It's the second time in just a few days that I see blog comments attack Atlas on its compatibility layer. I've tried to explain a few days ago why we made this design choice but I think it deserves an even more detailed explanation...

There are basically three ways you can make a library cross-browser.

  • You can detect capabilities every time you need them. If you do that, all new code must take all browsers into account. Adding a new browser means touching all of the code base.
  • You can write an abstraction layer that creates another API that abstracts the concrete APIs of each browser. This is no more standard than the other two ways as you're really introducing a new proprietary API on top of the existing standard and proprietary ones.
    Furthermore, this is making the code path longer as each use of the API must go through an additional function call and must redo the capability check every time it's called.
  • Finally, and this is what Atlas is doing, you can extend one or several of the browsers to make all browsers consistently callable. In this case, the code path is the most direct and the capability detection happens only one time, when the compatibility layer is created. An additional advantage of this technique is that you can add a new browser by simply writing its compatibility layer, without having to touch the actual library.

Now, why did we extend Firefox and Safari and not IE? Simply because Firefox and in a lesser extent Safari are far more extensible than IE. For example, you can modify the prototype of HTML elements and thus act once to extend all instances of all elements. Firefox goes even further by allowing the definition of getters and setters for element properties. If IE had the same extensibility, we would happily have made it converge to the standard instead of bringing Firefox and Safari to implement the IEisms. We would have absolutely loved that but it's simply not possible.

There is no malice there, purely technical reasons.

Furthermore, let me point something out. It's very well that Safari and Firefox follow the standards when they exist and I'm glad they do but it's not enough for Ajax applications because they *all* rely on non-standard capabilities. XmlHttp is not a standard for example.

Here's another example where despite its excellent adherence to standards, Safari is making things difficult: how do you dynamically load arbitrary script and get notified when the script is done loading? Well, Safari has only recently implemented dynamic script loading but as far as I know (and the documentation is far from sufficient on this subject) there is no way you can get notified when it's done.

Comments

Olivier said:

De toute façon dès qu'on essaye de faire un produit qui va satisifaire tout le monde Microsoft comme libre, ça geule du côté libre ...
Faut pas trop se prendre la tête, Atlas ROCKS!!! ;)

Continuez votre bon boulot les gars!
# April 14, 2006 4:27 AM

Richard Hillman said:

How will IE7 affect this?
# April 14, 2006 9:13 AM

Keith said:

I believe what you are doing is good. But I ran into a problem with an open source javascript calendar that wouldn't work in Firefox because the compatiblity layer made the events IE like and the calendar knew it was running under Firefox. This was with the March CTP. Maybe it was fixed with the April CTP, but I haven't tested it. It is a basic mistake and I am surprised more 3rd party controls don't fail under Firefox.

I understand trying to make javascript with work all browsers is a difficult thing, god knows I do. It just means you guys really have your work cut out for you to not make mistakes like this.

http://forums.asp.net/thread/1256274.aspx
# April 14, 2006 9:20 AM

Scott said:

"Safari is making things difficult: how do you dynamically load arbitrary script and get notified when the script is done loading?"

Actually, I don't think Safari is supporting the standard here. From what I understand, the big sticking point is supporting onLoad for any DOM element. I belive the "standards" specifiy that onLoad should be supported on any HTMLElement, but safari only supports it on the BODY element. Been waiting, and watching the webkit repository, for them to support this for a while so live.com will work in Safari.

BTW, the Atlas tool kit has a lot of issues in Safari. It's odd that other toolkits, Dojo, Scriptaculous, Mochikit, etc... can get accordian panels and drag-drop workingin Safari, but Atlas can't. Perhaps the Atlas script library needs to be re-worked a little. It seems to me that MS started going down one architecture path with Atlas, and then checked to see what browsers worked with that architecture after the fact. Not sure if it's malace or lack of time. I always attribute anything that seems to be malace to a tight schedule instead.
# April 14, 2006 1:15 PM

Bertrand Le Roy said:

Keith: I don't understand. Is this component doing browser detection? If it is, that's why it's not working, not because of the Atlas compat layer. It should be doing capability detection, not browser detection.

Richard: this will affect IE7 only where they remove old IEisms from the object model, which they're not doing in a way that affects Atlas for the moment.

Scott: Drag and drop works in Safari. There are other things that don't work currently in Safari but we're not even in beta, so give us some time here.
# April 14, 2006 3:09 PM

Scott said:

Bertrand,

You're right. The drag drop does work in Safari. I just tried the Drag Panel example at the Atlas control toolkit page. I first tried the re-order list example and it did not work.
# April 14, 2006 5:26 PM

Bertrand Le Roy said:

Hey Scott, thanks for the heads up. I'll relay that to the right people. We're really committed to Atlas being cross-browser but there sure is some more work.
One thing that should probably be mentioned is that sometimes, when the compat layer method can't work, we're reverting to one of the other two.
# April 14, 2006 5:31 PM

Michael Geary said:

onload may not work in Safari, but you can certainly use dynamic script insertion, where the way you are "notified" is that your script runs. Combine this with a JSONP-style callback and you are golden.
# April 16, 2006 4:57 PM

Sander said:

But isn't the benefit of using the "detect capabilities" approach that when browsers will implement said capabilities your library will automatically work without you having to do any work to it?

Writing to capabilities seem to make more sense then writing to browsers as browsers change but capabilities won't (unless they get respecifieid of course).

Also you say about detecting capabilities:
Adding a new browser means touching all of the code base.

But if you write to capabilities it means it's browser independent, you don't have to add a new browser? I'm probably not understanding your argumentation fully but would be interested in hearing more about it. Thanks :)
# April 17, 2006 5:00 AM

AO said:

W3 XMLHttpRequest object standard (draft) - http://www.w3.org/TR/XMLHttpRequest
# April 17, 2006 8:40 AM

Bertrand Le Roy said:

Michael: we know how to work around it, it was more an illustration of the fact that standard-compliant browsers do not eliminate the need for a compat layer.
With the solution you describe, in the general case, you need the server's collaboration to inject the callback/notofication at the end of the script, or you need the script to be executable at a non-global scope (which is fine for data). It becomes more difficult if you need to be able to dynamically load and execute an arbitrary script and be notified. We know a way to do it but it doesn't work cross-domain, which limits its usefulness in an environment like live.com.

Sander: you misunderstood me. The important part about the first solution is not "detect capabilities", it's "every time you need them". In the third solution (the one we're using), we *are* detecting capabilities, but only once, when the compat layer is initialized. If a capability is not there, we implement it so the rest of the code can just assume it's there from this moment on.
Even writing like that, and even with standard-compliant browsers, there are things that you can't detect just by looking at capabilities because they are there but are implemented with subtle differences. The extension mechanism may also vary from a browser to another. All that makes it necessary to add new layers even with standard-compliant browsers (Opera would need a new compat layer for example).

AO: yes, I know, see this post: http://weblogs.asp.net/bleroy/archive/2006/04/14/442970.aspx
# April 17, 2006 3:28 PM

TrackBack said:

I guess I'm becoming a regular source of news for these guys :D I like that, I'm a fan. They're one of my main sources of tech news.
# April 19, 2006 3:41 AM

TrackBack said:

Shawn leads the Atlas Toolkit team.
# April 19, 2006 3:43 AM

TrackBack said:

I can't read a word there but it doesn't look like spam as far as I can tell...
# April 19, 2006 3:45 AM

Andrey Skvortsov said:

How about support of IE's event model?Is there onfocusout/onmouseenter/onmouseleave support in firefox?

Thanks.
# April 19, 2006 11:25 AM

Bertrand Le Roy said:

Andrey: there is support for the IE event model in general (attachEvent, detachEvent, window.event, etc.) but not for specific events for the moment. We may add these in the future if there's enough demand for it.
# April 19, 2006 4:33 PM

kris said:

hi,

i still don't understand why there is a full blown compatibility layer in Atlas. javascript, (x)html, css ... are all well defined by the w3c.

so if you use the standards (as they should be used) it will work in any modern browser. i'd say only in 5% you will have to to a dirty trick to make your scripts work in ie. because ie6's implementation of standards is quite poor.l

also there a so many opensource js libraries that already figured out the flaws of ie and correct them. just take a look at dojo, prototype, script.aculo.us, behaviour.js and so on. why reinvent the wheel?

regards,
kris

ps. i dont want to be rude.... just a little provocation with a hope of getting answers :)
# May 2, 2006 9:41 AM

Bertrand Le Roy said:

Kris: that's only the theory. I really wish it was true but it's not. The standard implementation is incomplete or inconsistent in *all* browsers (although I agree that IE6 is the worst on that point (but on the other hand, it implements non-standard stuff that's absolutely necassary like pixelLeft and that other browsers are slowly implementing despite the non-standardness because they are just useful and were oversights of the standards but I digress)). The incompleteness can especially be felt in Safari (example: the lack of onload event on all elements) and the inconsistencies comes from the fact that many standards are vague in places and open to interpretation.
Plus, the 5% you're talking about is a huge number for us as framework developers who need to make it as easy as possible for third party developers to develop new components. These 5% (or whatever is the real number) is precisely what we need to abstract. These are very complex problems that the average developer just hasn't time to investigate and solve. Look at how complex it is to get the pixel coordinates of an element relative to the top-left corner of the page. It is absolutely necessary to abstract that. Look at the differences in the event models (IE is the one that's wrong here of course but I don't care about who's wrong, I just need to fix it). We just can't constantly deal with two incompatible event models, we need to make that consistent.
It's absolutely true that there are already other libraries out there that do a good job at cross-browser support but you need to take into account that:
* they all have some form of compat layer even if it's implemented differently.
* they do a lot less than Atlas (none of them do anything like xml-script for example).
* Atlas has constraints that other frameworks don't have (such as back-compat with ASP.NET, including third-party controls).
* Atlas is not even in beta state. We're fixing bugs actively.
# May 2, 2006 12:54 PM

Jeff W. Barnes said:

A lot of cool stuff on the wire this week:

Consequence of leaving debug="true" enabled
Rick Strahl...
# June 12, 2006 4:18 PM

Colin said:

I really think you made the wrong decision with the compat layer and all the window.event stuff. If you're not going to adhere to standards, and you're creating such a rich, proprietary javascript API anyway, then why not have a new function for observing events like the Prototype Framework does with Event.observe()? Basically you're asking developers to learn a beautiful library which introduces things like inheritance, Atlas XML script, etc. Asking developers to learn two new functions: observe() and stopObserving(), for example, would be extremely trivial. Also, I think your worry about changing the entire code-base upon introduction of a new browser is unwarrented. A properly engineered system can simply provide self-registering strategies which would require no change to the code-base, only a new strategy file. E.g. //expose some function like: Atlas.MapEventModel( browserEventStrategy ){} Assuming that each browser/compatibility strategy implements the proper contract, all the functionality needed to map DOM events to the Atlas framework would be taken care of compositionally in an extensible and maintainable manner. As it is now, you're claiming that the reason you implmented the compat layer the way you did is because other browsers are extensible in ways IE isn't. This implies the assumption that any new browser that comes out will be as extensible as the rest which is very very dangerous. What if a browser comes out that doesn't allow you to hook up window.event? It's very possible! The suggested alternative, on the other hand, is more likely to be able to work around the quirks of browser/capability event incompatibilities present and future. Event handling would happen through a consistant interface that is easy to learn, and the underlying details of providing the mapping to the consistent interface would be properly encapsulated into files such that each are independently updatable and easy to introduce as new browsers with different capabilities come along.
# August 15, 2006 1:27 PM

Bertrand Le Roy said:

Colin: these are great points. We had arrived to the same conclusion about the extensibility of the model. The new solution we're developing is more conventional and won't perform as well, but it will be easier to add new browsers even if they don't provide good extensibility points.

Fortunately, Atlas did not ship yet, so we can still take user feedback into account and revise what seemed to be good decisions at the time.

# August 15, 2006 2:03 PM

Colin said:

That's very good to hear! I'm consistently impressed by the overall coolness of Atlas and am excited to see it grow. There are a few kinks to work out, but I have no doubt the Atlas client libraries will eventually wipe the floor with other AJAX/JavaScript frameworks.
# August 15, 2006 3:13 PM

Atlas and more said:

In previous CTPs, the client-side DOM event model was the IE model. You would use attachEvent and get

# November 6, 2006 7:26 PM

Ali Muhammad said:

Dear freinds,

I have a web application developed in vb.net. I use

Atlas Timer control to update my update panel . This application working fine on internet explorer but not envoking timer in fire fox... any buddy hving clue kindly help me

Regards

Ali.

# January 30, 2007 11:01 PM

Bertrand Le Roy said:

Ali: please contact me through the contact form of this blog.

# January 31, 2007 12:14 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)