Monday, 23 January 2006
How Web-Ready is XMLHttpRequest?
I’ve been playing around with some ideas that use XMLHttpRequest recently, but I keep on bumping up against implementation inconsistencies on IE vs. Safari vs. Opera vs. Mozilla. Although the interface exposed is pretty much the same, what it does in the background is very different, especially with regards to HTTP.
For example, some implementations will handle redirects and cache validation for you, while others will pass through the HTTP status codes, expecting you to pick up the pieces. This gets really annoying when you’re trying to use the Web to your advantage, rather that just make HTTP into another RPC protocol (which so many AJAX apps do… but I digress).
Frustrated by this and with a bit of spare time last week, I put together a set of tests for HTTP functionality in XMLHttpRequest (and friends). It’s fairly rough right now, but it’s already been useful to me. The fun part is it’s implemented on the server side with plain files and .htaccess magic (mostly mod_rewrite and mod_asis).
So far, the most bizarre thing I’ve come across is Safari’s inability to pop up an authentication dialog if you’re using XMLHttpRequest synchronously, even though it’s happy to do so if you’re working async. Basic redirect support is pretty universal, but things quickly fall apart on most browsers when you do tricky things like use non-GET/POST methods on redirecting resources. IE 6 is actually one of the better implementations I’ve tried so far (maybe not so surprising, considering they came up with it).
Anyway, give it a try; I need to work on the documentation and some of the tests, especially around caching. Ideally, I’d like to get some sort of result collection / summary thing going (and I’ve left a hook for it), but for now, it’s interesting to just look at (and maybe print) the per-browser results.
Feedback and suggestions appreciated below.