Assuming you control the contents of your script, you can put some code to execute at the bottom of your lazy loaded script to indicate to the main page that the script has loaded. For example, in your page you can do something like this:
var loadingScripts = 0;
var loadScript = function() {
// Do what you need to do to load the script...
loadingScripts++;
}
var loadedScript = function() {
loadingScripts--;
if (loadingScripts == 0) {
// Kick off execution of code that requires the lazy loaded scripts.
}
}
Then in your script, you'd add this code to the bottom:
loadedScript();
You can spice this example up with an array instead of an integer (to keep track of which specific scripts have loaded). You could also use an object instead to associate particular function calls with the completion of particular scripts. I kept my example simple, but ask if you want me to show how to do extend the code.
Here is how you can use a callback to continue execution of specific code upon loading of a script (again, assuming you control the scripts themselves).
var scriptCallbacks = {}
var loadScript = function(scriptname, callback) {
// Do what you need to load scriptname
scriptCallbacks[scriptname] = callback;
}
var loadedScript = function(scriptname) {
(scriptCallbacks[scriptname])();
}
Then when you want to load a script, you do something like this...
var callback = function() {
// Write exactly what you want executed once your script is loaded
}
loadScript("MyScript.js", callback);
And again, in your lazy loaded script, just add this code to the bottom to inform your callback to fire:
loadedScript("MyScript.js");