0

To call all js files in just one line on my header I am currently using

function alljs(jsfile) {
    var src = document.createElement("script");
    src.setAttribute("type", "text/javascript");
    src.setAttribute("src", jsfile);
    document.getElementsByTagName("head")[0].appendChild(src);
}

alljs("path/to/my/jsfile1.js");
alljs("path/to/my/jsfile2.js");
alljs("path/to/my/jsfile3.js");

then all I have to do is put this on my header:

<script type="text/javascript" src="my/path/all.js" ></script>

but recently I have to include jquery files in my system I notice that calling a jquery file by adding

alljs("path/to/my/jqueryfile1.js");

to my all.js file doesn't work... I have to do a second line of <script> on my header just to call the jquery file...

My question is: is there a similar way to call all jquery files in just one file?

nekomancer
  • 69
  • 1
  • 4
  • There are lots of approaches to combining your js for deployment (you can look into webpack and similar tools for a much more robust solution, but also not easy to implement). See this answer for some fairly simple approaches to combining your js files https://stackoverflow.com/questions/5511989/combine-multiple-javascript-files-into-one-js-file – benvc Jul 12 '18 at 23:43
  • https://stackoverflow.com/questions/5235321/how-do-i-load-a-javascript-file-dynamically – Gautam Patadiya Jul 13 '18 at 04:05

0 Answers0