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: 
What about using a server-side script to generate the script tag lines? Crudely, something like this (PHP) -

```
$handle = opendir("scripts/");

while (($file = readdir($handle))!== false) {
    echo '<script type="text/javascript" src="' . $file . '"></script>';
}

closedir($handle);

```
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);
   } 
 }

```