All in the <head> – Ponderings and code by Drew McLellan –

Version Targeting and JavaScript Libraries

The discussion about version targeting continues. In Version Two Eric writes:

The handling of JavaScript libraries in a world where the pages calling the libraries will determine how the JS is interpreted – that’s definitely something I hadn’t considered. As I understand it, the problem case is one where a JS library that uses (say) IE9 features is loaded into a page that triggers the IE7 engine. The library would need to preserve backward compatibility with all the IE versions that could be used.

But isn’t that already the case? Every library whose source I’ve studied has all kinds of detection, whether it’s feature or browser detection, in order to work with multiple browsers. I would think that under version targeting, the same thing would be necessary: you do feature detection and work accordingly. Again, it’s entirely possible I missed something there, so feel free to let me know what it was.

The issue with JavaScript libraries (and embedded widgets) is an important one. Eric is right that libraries have to already cope with multiple browser versions, of course. The difference is that, over time, those old versions disappear. A library or widget developed today doesn’t need to really take IE5 or even IE5.5 into account because those browsers have gone away to an extent that it’s acceptable to not serve them your page’s behaviour layer (a la Yahoo’s Graded Browser Support).

The difference with version targeting is that IE7 ‘mode’ is never going to go away. Fast-forward to 2012 when the current version of IE is IE11, but there’s still a good proportion of IE10 in the marketplace. A JavaScript library has to include conditions not just around any quirks in IE10 and IE11, but also all those quirks from IE7.

If there happen to be any differences in the way IE7 mode is implemented, the library may even need to cope with IE10’s IE7 mode and IE11’s IE7 mode. If the library does anything with CSS (for example a drag and drop script) variations in CSS rendering across all those implementations has to be taken into account too.

Developing for the current browser plus the previous version is inconvenient but readily achievable. Developing for the current version, the previous version and a version 4 years old is not only a nightmare, but also limits the functionality you can use and slows the progress of the web.

With version targeting, IE7 will never go away. Just as browsers are born, they must also die and make way for the next generation.