Using RequireJS to Load the Right Version of jQuery Depending on Internet Explorer Version

0 minute read

Here’s a cool trick you can use with RequireJS. I found it in a post by @rnsloan called Conditionally Loading jQuery 2.x.

Since environments with SharePoint can often have a mixed bag of browser versions, this conditional setting lets us load jQuery 2.x when the browser can handle it (generally IE 9+) or jQuery 1.x when it can’t. The function document.addEventListener is undefined in IE8 and earlier – sometimes called oldIE – and defined in IE9+ – also known as modern.IE – so it’s a simple little test that ought to work.

If you don’t know why this matters, check out the Browser Support page on the jQuery site.

  paths: {
    "jquery": (document.addEventListener) ?

Note: The versions of jQuery above were current as of this writing, but may well have already moved on by now.


Have a thought or opinion?