Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  43] [ 1]  / answers: 1 / hits: 65547  / 12 Years ago, thu, june 28, 2012, 12:00:00

Possible Duplicate:

How to include js file in another js file?






Suppose I have a few JavaScript source files: a.js, a1.js, and a2.js. Functions of a.js invoke functions from a1.js and a2.js.



Now I have to declare all these files in my HTML page. I would like to declare only a.js in the HTML and import/include a1.js, and a2.js in the a.js source file.



Does it make sense? Can I do that in JavaScript?


More From » client-side

 Answers
45

You can't specify imports in vanilla javascript.



So your solutions (excluding heavy server side frameworks) are :




  • simply do the imports


  • concatenate your js files (and minify them in the same move, for exemple using the closure compiler)


  • use a module itool like require.js




As long as you're not experienced, and if your number of files is low (less than 15), I recommend to simply choose the first or second solution. Using a module loader may have side effects you don't want to debug when beginning to learn javascript.


[#84590] Wednesday, June 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
makaylahk

Total Points: 166
Total Questions: 94
Total Answers: 117

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;