Javascriptdependencyresolution

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:

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.