MSXML versions and XMLHttpRequest
2007-04-04 08:32:00
I got an e-mail this past week with an interesting question from a guy who was reading my Ajax book:
why you do the check for 'Msxml2.XMLHTTP' instead of 'Msxml2.XMLHTTP.6.0' which is apparently the latest release from Microsoft that has numerous improvements?
Naturally, I had an incredibly well-throught-out rationale for it -- "because that's how I originally did it, and it works." I had seen examples in the wild of using different specific program IDs (i.e., versions of the MSXML library) to get an XMLHttpRequest object, but never gave it much thought since my own code manifestly was working without.
Sure, "does it actually work" is the acid test -- no one cares how superbly designed your API is if they can't use your frigging app. But still, it's good to have someone ask these kinds of questions, so after the initial "ummm ..." reaction, you can get yourself educated. Otherwise it's all just cargo cult programming.
His initial e-mail kicked off a bit of discussion, and in the back-and-forth, there were some interesting links unearthed.
- An unintentionally funny exchange where Eric Pascarello ("Ajax in Action," Manning) tries his damndest to help with an MSXML question, but seems to be totally misunderstanding what the guy is asking.
- A fairly succinct explanation of why you don't need to get too torqued up about which specific version of MSXML you're using.
- The guys at BrainJar go to 11 (okay, it's actually going to 7.0, whatever) checking for all possible progIDs.
The bottom line, according to this post the Microsoft XML Team's Weblog, is that you should try to use MSXML 6.0 if you can, and if it's not available, you should fall back to MSXML 3.0:
Use MSXML 6.0 - it is "in the box" on Vista and available for download on Win2k, XP, and 2003. It has the best security, performance, reliability, and W3C conformance
MSXML 3.0 is our preferred "fallback" -- It is installed on every OS from a fully patched Win2k SP4 installation on up, so it requires "zero-deployment" and is serviced regularly with the OS
You can read for yourself what they say about the other version numbers on the blog post, but they don't recommend using them.
Using no program ID at all (e.g., new ActiveXObject('Msxml2.XMLHTTP')
) will give you version 3.0. (From the blog post: "The version-independent ProgID is always bound to MSXML 3.") That's why it's no real sweat to be invoking the XMLHttpRequest object with no progID -- you get MS's preferred fallback anyway, so it works just fine. You just don't get the most up-to-date kung fu.
I've updated the XHR library for Fleegix.js to take this new info into account. That change, and a bunch of bugfixes make this newest one version 0.3.1.