Show TOC

Avoiding DuplicatesLocate this document in the navigation structure

The dependency resolution tool avoids duplicates by wrapping embedded modules with a few lines of additional coding.

When the runtime dependency resolution is used, the runtime maintains a list of the loaded modules. This list is searched before a new module is loaded and executed. If the requested module is on the list, the module is not loaded again.

However, if a server or build-time tool is used instead, it creates a bigger file which may contain multiple modules. The runtime can only check if the bigger module has been loaded already, but does not know about the contained modules. In this case, it is not possible to avoid double-loading the modules. To avoid this, the embedded modules are wrapped with a few lines of additional coding. This is evaluated during execution of the merged module and has the same effect as the original runtime checks in an unmerged scenario:


    // code of enclosing module 

    // location of a'xyz');

    if ( !'xyz') ) { // check whether module 'xyz' has been loaded already
      'xyz'); // will only be added if the module 'xyz' doesn't contain a declaration

        // original text of module 'xyz'

    // further code of enclosing module
Note The generated wrapper coding also contains a module declaration if the module does not contain one. The wrapper avoids double loading no matter whether a module has been loaded as an individual file or as part of a bigger, merged module. It is even possible to recursively merge files (merged module A includes a merged module B).