1

I am not sure what to call this question so any revise is welcomed!!! I am trying to learn to keep a clean js library structure of third party scripts as well as my own. I have no knowledge other than the basic method of adding js files to my page other than the old way..

I found this on searching and it makes some sense to me seeing that I am not real good with javascript or jquery https://github.com/volojs/create-template

my question is I have a folder structure as follows

  • index.html
  • assets/js/lib/gsap/
  • assets/js/lib/bootstrap/
  • assets/js/lib/whateverelse

in my index.html file i have my link to jquery and to the file called app.js

but I am confused on how to get this to work how to i call the files from the directory?

Basicly I want to call multi js files from 1 file

3
  • 1
    <script src="./assets/js/ib/bootstrap/bootstrap.min.js" ></script> Commented Jun 8, 2018 at 19:34
  • yes I understand how to add the script using a link I am asking how to call all of them from 1 js file not 9 different requests Commented Jun 8, 2018 at 20:05
  • I think you can't do that with js Commented Jun 11, 2018 at 1:48

1 Answer 1

0
+50

If I understood correctly u need files included from app.js and app.js included in index.html.

app.js

function dynamicallyLoadScript(url) {
var script = document.createElement("script"); // Make a script DOM node
script.src = url; // Set it's src to the provided URL

document.head.appendChild(script); // Add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead)
}
dynamicallyLoadScript('assets/js/lib/bootstrap/test.js');
dynamicallyLoadScript('assets/js/lib/gsap/test.js');

index.html

<script src="app.js"></script>

function taken from here. Guy answers almost all the related questions.

Sign up to request clarification or add additional context in comments.

Comments