Insert this in your javascript:
var LoadedScripts = new Array(); jQuery.getScript = function(url, callback, cache){ if ($.inArray(url, LoadedScripts) > -1) { callback(); } else { LoadedScripts.push(url); jQuery.ajax({ type: "GET", url: url, success: callback, dataType: "script", cache: cache }); } };
How to use it:
function YourFunction() { jQuery.getScript('path/to/your/script.js',function(){ // your code here - the script has loaded },true); }
change "true" to turn cache off and force reload of file (useful for css)
function YourFunction() { jQuery.getScript('path/to/your/script.js',function(){ // your code here - the script has loaded },false); }