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:
#!js ... // code of enclosing module ... // location of a jQuery.sap.require('xyz'); if ( !jQuery.sap.isDeclared('xyz') ) { // check whether module 'xyz' has been loaded already jQuery.sap.declare('xyz'); // will only be added if the module 'xyz' doesn't contain a declaration // original text of module 'xyz' ... } ... // further code of enclosing module ...