Question: I have a bunch of JavaScript files that I would like to include in the page, but I don't want to have to keep writing 

```
<script type="text/javascript" src="js/file.js"></script>

```

So is there a way to include all files in a directory (unknown size)? Can I do something like...

```
$.getScript("js/*.js");

```

... to get all the JavaScript files in the "js" directory? How can I do this using jQuery?

Answer: 
Given that you want a 100% client side solution, in theory you could probably do this:

Via XmlHttpRequest, get the directory listing page for that directory (most web servers return a listing of files if there is no index.html file in the directory). 

Parse that file with javascript, pulling out all the .js files. This will of course be sensitive to the format of the directory listing on your web server / web host.

Add the script tags dynamically, with something like this:

```
function loadScript (dir, file) {
 var scr = document.createElement("script");
 scr.src = dir + file;
 document.body.appendChild(scr);
 }

```
It can be done fully client side, but all javascript file names must be specified. 
For example, as array items: 

```
function loadScripts(){
   var directory = 'script/';
   var extension = '.js';
   var files = ['model', 'view', 'controller'];  
   for (var file of files){ 
       var path = directory + file + extension; 
       var script = document.createElement("script");
       script.src = path;
       document.body.appendChild(script);
   } 
 }

```