Show TOC

Loading a ModuleLocate this document in the navigation structure

For loading a module, SAPUI5 provide the function.

In a first step, the SAPUI5 framework initializes and loads the sap.ui.commons.MessageBox module. The framework analyzes the module name and derives the module URL from it by replacing all dots ('.') with slashes ('/') and appending the standard suffix '.js': ./resources/sap/ui/commons/MessageBox.js. This URL is used to load the module as a text.

The following code snippet shows an example:

<!-- UI5 bootstrap tag -->
    <script id="sap-ui-bootstrap" src="./resources/sap-ui-core.js" data-sap-ui-libraries="sap.ui.commons"></script>


        function onPressButton() {
            sap.ui.commons.MessageBox.alert("Hello World!");


If the loading succeeds, the module is declared with the original module name and then executed in a global context (window). If either the loading of the module or executing the module fails, the module name is internally marked as "failed" and an exception is thrown indicating the cause. Any further tries to load the same module will fail and the same error message is issued.

This ensures that the required module has been loaded and executed before the execution of the caller continues, unless cyclic dependencies occur.