I have split my javascript in different files. I want to prevent, that javascript files are loaded twice. How can I do that?
Here's a test to see if a script has been included based on the path to the js file:
function isScriptAlreadyIncluded(src){
var scripts = document.getElementsByTagName("script");
for(var i = 0; i < scripts.length; i++)
if(scripts[i].getAttribute('src') == src) return true;
return false;
}
It will work for all scripts not loaded through AJAX, though you may want to modify it if you have jsonp code running.