I want to load a Javascript file on the click event instead of loading at the page load event, for performance reasons. Is there anyway to know that particular if javascript is already loaded?
Right now I am maintaining a global variable to check the 'loaded' event
var javascriptLoaded=false
if (!javascriptLoaded)
$.getScript('/scripts/test.js', function() {
javascriptLoaded = true;
setTimeout(function() {
callSomeFunctionhere();
}, 1000);
});
Is there any better way of doing this?