题意:"如何避免在 UI5 中出现“主线程上的同步 XMLHttpRequest”警告?"
问题背景:
I'm staring my UI5 with the following bootstrapping in index.js
:
"我在 `index.js` 中使用以下引导程序启动我的 UI5:"
sap.ui.define([
"sap/m/Shell",
"sap/ui/core/ComponentContainer"
], (Core, Shell, ComponentContainer) => {
"use strict";
new Shell("", {
app: new ComponentContainer("", {
height: "100%",
name: "webapp"
}),
appWidthLimited: false
}).placeAt("content");
});
According to the UI5 documentation:
"根据 UI5 文档:"
Static dependencies are loaded in the dependency declaration array of the
sap.ui.define
call. These dependencies are always loaded in advance before executing the defined module.
Do I understand it correctly that in such case the modules will be always loaded in a synchronous way and there is no real way to avoid the «Synchronous XMLHttpRequest on the main thread» warning?
"我是否正确理解,在这种情况下,模块将始终以同步方式加载,并且没有真正的方法可以避免“主线程上的同步 XMLHttpRequest”警告?"
Can I, perhaps, just wrap new sap.m.Shell(sId?, mSettings?)
with async
/await
?
"我是否可以仅仅用 async/await 将 `new sap.m.Shell(sId?, mSettings?)` 包裹起来?"
Update #1:
I've checked the loading with ?sap-ui-xx-nosync=warn
and got the following results:
"我使用 `?sap-ui-xx-nosync=warn` 检查了加载情况,并得到了以下结果:"
For some reason i18n/i18n_en.properties
is loaded synchronously. The only place where I'm accessing the i18n
is:
"出于某种原因,`i18n/i18n_en.properties` 是同步加载的。我访问 `i18n` 的唯一地方是:"
const oBundle = myI18nModel.getResourceBundle();
But following the documentation, I could not grasp why myI18nModel.getResourceBundle()
leads to the synchronous loading.
"但是根据文档,我无法理解为什么 `myI18nModel.getResourceBundle()` 会导致同步加载。"
Update #2:
After a deep exploration of no sync XHR sample, I found out the reason for the sync XHR
warning. That was "description": "{
{appDescription}}"
and "title": "{
{appTitle}}"
in manifest.json
which is explicitly noted:
"经过对无同步 XHR 示例的深入探讨,我发现了同步 XHR 警告的原因。那是 `manifest.json` 中的 `"description": "{ {appDescription}}"` 和 `"title": "{ {appTitle}}"`,文档中明确指出:"
"title": "Here the i18n bundles can't be loaded with 'async: true' yet!",
"description": "Same here. Hence, no 'i18n' in this 'sap