2

Let's say I have folder scripts with 10 javascript files and instead of doing this:

<script src="scripts/js1.js"></script>
<script src="scripts/js2.js"></script>
<script src="scripts/js3.js"></script>
<script src="scripts/js4.js"></script>
<script src="scripts/js5.js"></script>
//and so on...

I want to do this:

<script src="scripts/*"></script>

which load ALL files in scripts

How would I go about doing this?

  • I think your first hurdle would be that if you are looking for a client-side only solution, that the script running on the client has no idea what files are in the folder on the server. – Elad Lachmi Mar 20 '16 at 16:42

2 Answers2

1

Won't be as easy as that, here is what you are looking for:

How can I include all JavaScript files in a directory via JavaScript file?

Community
  • 1
  • 1
theblindprophet
  • 7,767
  • 5
  • 37
  • 55
-1

What you try to achieve is cumbersome from the client side. You can achieve the same through server-side scripting before you load your html file. You can use a task runner tool like grunt, gulp etc. (or write a script) that will traverse your target directory, retrieve all the *.js file paths and append their script tags in your html file.

Another solution is to use a tool to concatenate all your js files in one bundle file and only load that file from your html file. There are plenty of tools out there to do that

jahnestacado
  • 593
  • 3
  • 9