In the application I'm developing I need to include some javascript files dynamically after the page is loaded. How to acheive this?
2 Answers
You can load a script resource dynamically using the following function
function loadScript(src){
var script = document.createElement("script");
script.src = src;
document.body.appendChild(script);
}
Here we are creating a script element dynamically and add that to the DOM structure of the page.
If you are using jQuery, you can use the getScript() method to fetch a script resource dynamically.