Can I get a Javascript resource to load another?

I have a script in which I want a web page to contain <link>one Javascript resource, and this resource downloads two other Javascript resources from the same web server. Is it possible? Can this be done independently of the browser?

This may seem a little unusual, but there are complex reasons why I would like to do this, and why combining resources into a single file ... is inconvenient.

+5
source share
2 answers

If I am not mistaken, Javascript Resource is nothing but your * .js files, right? That way you can include any number of js on your tagged page <script>. eg.

<script type="text/javascript" src="MyDomain/js/abc.js"></script>
<script type="text/javascript" src="MyDomain/js/xyz.js"></script>

In addition, in one js file, you can import another js file by calling the following function:

function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>'); 
}

EDIT:

Or another way to write the same function:

function includeJS( jsPath )
{
    var js = document.createElement("script");
    js.setAttribute("type", "text/javascript");
    js.setAttribute("src", jsPath);
    document.getElementsByTagName("head")[0].appendChild(js);
};

Call these functions inside the js file.

+4
source

It looks like what you are looking for is usually called a javascript query request

+1
source

All Articles