I have a requirement where I want to execute one function just before the script is starting to load and also execute a function when the script is done loading and executing.
For example, I have the following script attached dynamically to the DOM.
var myScript = $('<div></div>').html("<script src='foo.js'></script>");
document.body.appendChild(myScript);
I want to execute a function showSpinner() before the script starts to load and execute.
and finally, want to execute the function hideSpinner() after the above script is done loading and executing the script.
Note:- I don't want to use any inline code or add a new script file to the server.