Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Enable async loading via async attribute of bootstrap script tag #647

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const UI5BundleFormat = {
outW.writeln(`sap.ui.requireSync("${ModuleName.toRequireJSName(moduleName)}");`);
},

bootCore(outW) {
outW.writeln("sap.ui.requireSync(\"sap/ui/core/Core\").boot();");
},

shouldDecorate(resolvedModule) {
return resolvedModule.executes(UI5ClientConstants.MODULE__JQUERY_SAP_GLOBAL);
}
Expand Down Expand Up @@ -96,6 +100,14 @@ const EVOBundleFormat = {
outW.writeln(`sap.ui.requireSync("${ModuleName.toRequireJSName(moduleName)}");`);
},

bootCore(outW) {
outW.writeln("if (sap.ui.loader.bootAsync) {");
outW.writeln(" sap.ui.require([\"sap/ui/core/Core\"],function(oCore){oCore.boot();});");
outW.writeln("} else {");
outW.writeln(" sap.ui.requireSync(\"sap/ui/core/Core\").boot();");
outW.writeln("}");
},

shouldDecorate(resolvedModule) {
return resolvedModule.executes(UI5ClientConstants.MODULE__UI5LOADER) ||
resolvedModule.executes(UI5ClientConstants.MODULE__UI5LOADER_AUTOCONFIG) ||
Expand Down Expand Up @@ -202,11 +214,13 @@ class BundleBuilder {
}

closeModule(resolvedModule) {
/* TODO: is this still required? This seems to be redundant
because the core is already booted when the requires are added.
if ( resolvedModule.containsCore ) {
this.outW.ensureNewLine(); // for clarity and to avoid issues with single line comments
this.outW.writeln(`// as this module contains the Core, we ensure that the Core has been booted`);
this.outW.writeln(`sap.ui.getCore().boot && sap.ui.getCore().boot();`);
}
}*/
if ( this.shouldDecorate && this.options.addTryCatchRestartWrapper ) {
this.outW.ensureNewLine(); // for clarity and to avoid issues with single line comments
this.outW.writeln(`} catch(oError) {`);
Expand Down Expand Up @@ -495,9 +509,13 @@ class BundleBuilder {

writeRequires(section) {
this.outW.ensureNewLine();
section.modules.forEach( (module) => {
this.targetBundleFormat.requireSync(this.outW, module);
});
if (section.modules.length === 1 && section.modules.includes(UI5ClientConstants.MODULE__SAP_UI_CORE_CORE)) {
this.targetBundleFormat.bootCore(this.outW);
} else {
section.modules.forEach((module) => {
this.targetBundleFormat.requireSync(this.outW, module);
});
}
}
}

Expand Down