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

```
@jellyfishtree it would be a better if you create one php file which includes all your js files from the directory and then only include this php file via a script tag. This has a better performance because the browser has to do less requests to the server. See this:  

*javascripts.php:*

```
<?php
   //sets the content type to javascript 
   header('Content-type: text/javascript');

   // includes all js files of the directory
   foreach(glob("packages/*.js") as $file) {
      readfile($file);
   }
?>

```

*index.php:*

```
<script type="text/javascript" src="javascripts.php"></script>

```

That's it!  

Have fun! :)