Skip to content

Runtime ~ Automatic Class Loading

Frank Wienberg edited this page Mar 14, 2014 · 1 revision

Automatic Class Loading

Automagic, sorry, automatic class loading is Jangaroo's ability to detect the set of classes needed to run a main class, i.e. the set of transitive imports or dependencies of that class.

Imagine a project with many, many classes (after all, we claim to support "programming in the large"). Wouldn't it be nice to only specify the main class to start from, and Jangaroo took care of loading all dependent classes? It is already possible!

The Jangaroo compiler passes all import directives to the Jangaroo runtime. The runtime keeps a list of all loaded classes and schedules any imported, but not yet loaded class for loading. The method joo.classLoader.run(className, ... rest) waits until all needed classes are loaded, and, in analogy to Java, simply invokes the static main method of the given class with the rest parameters.

This leads to all classes that comprise your Jangaroo application being loaded by single requests. While this is a great advantage during debugging and not as slow as you might think (after all, JavaScript files are cached by the browser), for deployment of your Web site, you will want less requests. Thus, Jangaroo pre-loads all generated code of each module as one request loading one JavaScript file (i.e. one request per used module), unless you request the page in debug mode (#joo.debug, see debugging tutorial).

If you want to prevent the deployed version from being switched into debug mode, simply add the following script to your page to hard-wire the debug mode to "off":

<script type="text/javascript">
  joo = { debug: false };
</script>
<script type="text/javascript" src="joo/jangaroo-application.js"></script>

Note: You have to set the joo object before including the Jangaroo application script!

You can then also spare deploying any files under target/.../joo/classes, since these are only used in debug mode.

For a later Jangaroo version, we plan a build mode where in deploy mode, not all classes of used modules are loaded, but like in debug mode only those (transitively) required by the main class.

Clone this wiki locally