I'm working on a small JS library that requires jQuery and Raphael. I've documented this fact in the README, but I don't love the idea that users have to manually include three JS libs to use this.
What are the pros and cons of having the library dynamically include the dependencies if it doesn't find them? Like so:
if (!window.jQuery) {
var _my_script=document.createElement('SCRIPT');
_my_script.type='text/javascript';
_my_script.src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js?';
document.getElementsByTagName('head')[0].appendChild(_my_script);
console.log("Loaded jQuery");
} else {
console.log("jQuery already loaded");
}
// get Raphael if not found
if (typeof(Raphael) === "undefined") {
var _my_script=document.createElement('SCRIPT');
_my_script.type='text/javascript';
_my_script.src='//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js?';
document.getElementsByTagName('head')[0].appendChild(_my_script);
console.log("Loaded Raphael");
} else {
console.log("Raphael already loaded");
}
Kosher?