Auto include javascript file if not already included-Collection of common programming errors
Well if that JavaScript file defines a specific variable (or a function) you can check its presence by checking typeof that_variable
, then load the JavaScript file if necessary. An example, here is how you load swfobject library if its not available on the page:
if (typeof swfobject == "undefined") {
var e = document.createElement("script");
e.src = "http://ajax.googleapis.com/ajax/libs/swfobject/2/swfobject.js";
e.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(e);
}