1 min read

Load jQuery without using conditional comments.

The BBC’s Responsive News is a great source of how to deal with everyday front end problems because they have to solve them for a much larger audience.

if('querySelector' in document
&& 'localStorage' in window
&& 'addEventListener' in window) {
// Add jQuery 2.0+
document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"><\/script>')
} else {
// Add jQuery 1.9.0+
document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"><\/script>')
view raw loadjquery.js hosted with ❤ by GitHub

There is an excellent slidedeck which gives more context to the above code as well as many more useful techniques.