Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

We have a team working on an ExtJS web app. Right now, the interface and its functionality is all stuffed in one 1500-line JS file, which is of course terrible. It's bad form in general, of course, but it really makes merging changes a bear.

Since Javascript doesn't have a #include or @require, or any other dependency-specifying mechanism, I'm at a loss how to gracefully split out functionality into smaller logical units, without requiring a great big laundry list of includes in the consuming HTML. I figure this is a common enough problem that somebody has worked out an elegant solution. Help?


migration rejected from stackoverflow.com Sep 26 '13 at 14:27

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by gnat, MichaelT, jmo21, Jim G., ChrisF Sep 26 '13 at 14:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – gnat, MichaelT, jmo21, Jim G., ChrisF
If this question can be reworded to fit the rules in the help center, please edit the question.

4 Answers 4

First, read JavaScript: The Good Parts by Douglas Crockford. There you will learn how to effectively use JavaScript's object structure, and various patterns that can help to divide your programs into reasonable pieces without putting every variable and function into the global namespace.

You will also want to use the Jasmine BDD framework to test your JavaScript. Because no matter how you slice it, 1500 lines of untested codes is well on its way to a BBOM


Well I am a 1 person team but there are a few things I do to keep myself sane:

  • First use JSLint on everything!

  • Keep things formated, I use a script to do this

  • small files, you can merge them before shipping the code if you want too

Use jquery or something similar.


Maybe you should have a look at Haxe. It is a compiled language (compiling to JS is one option) that allows you to split your source code into multiple modules.

However currently there are no recent ExtJS-wrappers. So you may have to wrap at least the part you really need.


try my little contribution to the github network. i hope you can enjoy it.


almost like the Node.JS require function, but for the browser.

- load and eval javascripts files once
- no appendChild command
- support sync and async XHR requests
- save the scripts on HTML5 Storage if available
- data transfer only if required, load scripts from storage or cache
if available (no transfer), otherwise load scripts via XHR (data transfer)

For developers, look into the file require5.js:

if(!global) var global = window.global = window;

// For development, IMPORTANT..!!! Ignore the cache and storage
if(false /** development??? Set this to true */){
if(!global.runUnitTest) global.runUnitTest = {};
global.runUnitTest.require = true;
global.runUnitTest.resolveUri = true;



Not the answer you're looking for? Browse other questions tagged or ask your own question.