Load external js file in another js file

javascript, jquery

Solution

If you want to include a JS file in a JS you can use jQuery.getScript() for that

$.getScript('another_file.js', function() {
    //script is loaded and executed put your dependent JS here
});

And if you cannot use jQuery

var imported = document.createElement('script');
imported.src = '/path/to/imported/script';
document.head.appendChild(imported);

Source

For more information about the current CSP3 spec from W3 look here.

Problem

I have this file include in my html and I want to call it from another javascript. Please suggest me how should I do it? ``` <script type="text/javascript" src="js.js">/* old:123 new: 456*/ </script> ``` I want to include it in my js file, not in the html.

Original source

Related problems