As we all know, JavaScript sucks in many ways, one of them being its lack of a module import system. So, if you have a substantial amount of JavaScript code, there are basically three choices:
stuff everything into one huge file,
break the code down into multiple files that load recursively by issuing multiple HTTP requests,
manually add all JS URLs, in carefully maintained order, to each and every page that needs them.
The first choice is unpleasant for the developer, whereas the second is unpleasant for the user (who gets to watch the sometimes slow loading). Approach 3 is unpleasant to both parties.
An alternative is to use dependency resolution between JavaScript files on the server side. The dependencies can be declared in JavaScript comments:
// requireScript script1, script2, script0815
The resolution is done in a servlet, whose URL is prefixed to the topmost JS file. In this way, one big JS file is assembled that can be sent in a single transaction. The file will include all required files recursively and in proper order, such that required files are always included before their dependent ones. The assembled JS file can be cached. The servlet file JSResolver.py contains additional explanations.