objectivity part III

August 13, 2004

objectivity part III

The Internet Explorer OBJECT woes are no more, thanks to XSLT. A while back, I came up with a way to implement <object type="image/*"> in IE using an HTC file to replace objects with imgs. Though it got the job done, it was slow as molasses.

While reading about custom DTD's, it dawned on me that there had to be a better way than my HTC approach. Because XML is extensible, it can be built upon (duh), and I remembered a great tutorial on W3 Schools about using XSLT to render XML in Internet Explorer and Netscape. Fast-forward a couple hours, and the IE Objectifier was born.

It is an extremely simple concept:

  1. Take an XML document
  2. Apply an XSL Transformation to convert it to something a browser will understand (XHTML)

This functionality has existed in IE since version 5. So in this scenario, our initial XML document is in fact an XHTML document. All we then need to do is apply a simple transformation to convert any object elements to img elements if they meet our criteria, and leave all other objects alone. And with that, we have "taught" IE how to handle objects.

This technique allows you to write completely valid XHTML 1.0 documents using objects in place of images, and it will render flawlessly across all modern browsers. The entire process takes place before any images are downloaded, meaning the page loads just as quickly, and it works whether scripting is on or off. And unlike images, objects allow you to have fallback content, rather than just alt text. The arguable downside is that if your XHTML is invalid, it will completely choke in IE. Personally I view this as a good thing, as it will keep designers honest and crappy code won't go unnoticed for long.

The other great thing about it is that it's very easy to set up—all you need is Apache and PHP, though I'm sure it can be done other platforms. Simply unzip this file in your document root, and you won't have to worry about it ever again (as long as you write valid xhtml). Try it out and tell me what you think.

Posted by jon at August 13, 2004 5:01 PM

Comments

Post a comment









Remember personal info?