Uffo
Uffo

Reputation: 10046

Split javascript in multiple files

So, I'm working on a big project where there is a need for a tone of JS, so I don't want to write everything in one file, just because it gets confusing working on it, and with the time will be even harder to keep track with everything.

So my plan is to split in multiple files and folders like.

js/home/register.js
js/home/login.js

But I want everything compiled in one files, I will like to use something like SASS has @import for styles, or something to take the files and compile automatically in one.

What's the best tool out here that you recommend guys?

Upvotes: 0

Views: 1062

Answers (2)

MarioDS
MarioDS

Reputation: 13063

Please see this SO question.

On linux you can use simple shell script https://github.com/dfsq/compressJS.sh to combine multiple javascript files into the single one. It makes use of the Closure Compiler online service so the resulting script is also effectively compressed.

The solution is to use whatever tool you like to combine the JS files before you upload them to your webserver. Dev environment != production environment. The only possible problem is that you create functions/variables with the same name, but then again I think there are tools to cope with that while joining them together.

Upvotes: 0

T.J. Crowder
T.J. Crowder

Reputation: 1074385

You can use any of several tools for this, including cat (on *nix systems) or copy (on Windows systems).

It probably makes sense to use a compiling / compressing / minifying / packing tool like the Closure Compiler, YUI Compressor, jsmin, or packer3. But which one you use is really up to you, the needs of your project, etc.

Upvotes: 3

Related Questions