1

I have two js files, a.js and b.js, now I want to create a common.js including the other two files. How can I do? Thanks in advance.

Hunter Zhao
  • 4,589
  • 2
  • 25
  • 39
  • 3
    At runtime? Build time? – Crescent Fresh Apr 26 '13 at 03:05
  • Are you willing to use PHP to do this? – orb Apr 26 '13 at 03:06
  • 2
    Check out this: http://stackoverflow.com/questions/4634644/how-to-include-js-file-in-another-js-file – Santosh Panda Apr 26 '13 at 03:07
  • @CrescentFresh build time, if i have a common js file so that I needn't import a.js and b.js one by one any more. – Hunter Zhao Apr 26 '13 at 03:14
  • @NobodyElse, the simplest way I've found is by running it through the C preprocessor (cpp) and just using `#include`. [CommonJS](http://wiki.commonjs.org/wiki/Modules/1.1) modules are another option; I have a simple build-time implementation in the form of M4 macros if you want it. – Dagg Nabbit Apr 26 '13 at 03:39
  • 1
    Are you working with JavaScript on the server side or are you actually serving scripts to browsers? Are you just tying to combine the files or are you trying to implement a modular design approach? This question is to vague and should probably be closed. – orb Apr 26 '13 at 04:05

1 Answers1

-1

Check this out : Require.js

It's a module-loader on client-side just like Node.js does, makes it easy to import js files or modules.

dyzdyz010
  • 2,256
  • 3
  • 16
  • 17