1

Possible Duplicate:
How to include multiple js files using jQuery $.getScript() method

I need to import multiple files within a .js file, I'm looking at the getScript jQuery method : http://api.jquery.com/jQuery.getScript/ but this just loads one file wheras I want to load 3.

Is there an alternative method for achieving this ?

Community
  • 1
  • 1
blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • http://stackoverflow.com/questions/11803215/how-to-include-multiple-js-files-using-jquery-getscript-method – 30thh Jan 14 '14 at 17:48

3 Answers3

3

You probably want something like this

var files = array('filename1', 'filename2');

for (var file in files) {
    $.getScript(file);
}
Schleis
  • 41,516
  • 7
  • 68
  • 87
0

You can call the getScript() method 3 times or as many times as the number of script files you want to import.

Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
0

you can do this like this, but you will have to call each of the scripts, and the order they load, in this example in file 3 we use the callback for executing a function.

$.get("js/file1.js")
.pipe($.get("js/file2.js"))
.pipe($.get("js/file3.js", {}, function()
{
    runFunction();
});
DadViegas
  • 2,263
  • 16
  • 12
  • **Deprecation Notice** $.pipe method is deprecated since jQuery 1.8. You can read more about it [over here](http://api.jquery.com/deferred.pipe/). Apart from that, this is a good mechanism. – Nis Mar 16 '14 at 22:28