3

I am in the process of writing a heavy Javascript app, which will ultimately be used by injecting one script into clients websites.

As of now I am writing all the modules in one JS file, however I am quickly finding that to be ineffective, as it feels very messy and cluttered, and I feel like the modules should all be in separate files.

My question is, what is a good approach to managing this. Should I write all the apps modules in separate files, and than compile them into one on the Server?

If it matters, I am using Node.js for my server.

1
  • 1
    This question isn't uninteresting but cannot receive a clear answer without discussion. It's possible it could be asked on programmers.stackexchange.com Commented Jul 12, 2012 at 14:58

2 Answers 2

2

First point : don't try to code everything in one file. Most big javascript applications contain dozens of files.

Use some kind of makefile to concatenate your js (and css) files. And after that use a minifier (I use Google Closure Compiler). To help debug, my deployement scripts always make two versions in parallel : one non concatenated/minified and one concatenated/minified. The uncompressed version enables the development/test onsite without any deployement operation.

This means that, as for all big application development, you need some kind of deployement toolchain to orchestrate the operations. This may be based on shell scripts, maven, ant, etc.

Secondly : use classes (without abuse, javascript isn't really OOP) and namespaces to clearly isolate your functions.

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

1 Comment

I do things the exact same way, and I gotta say it works very well for me.
1

Yes, keep all your files logically separate and then minify and combine them as a publish step or on the fly when serving them. Scott Hansleman wrote a very good blog post on why you should do this here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.