如何避免UI5中出现“主线程上同步XMLHttpRequest”警告?

如何解决如何避免UI5中出现“主线程上同步XMLHttpRequest”警告?

我在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");
});

根据UI5 documentation

静态依赖项被加载到sap.ui.define调用的依赖项声明数组中。 这些依赖项总是在执行定义的模块之前预先加载。

我是否正确理解,在这种情况下,模块将始终以同步方式加载,并且没有真正的方法来避免«主线程上的Synchronous XMLHttpRequest»警告?>

也许可以只用new sap.m.Shell(sId?,mSettings?) / async包装await吗?

更新#1:

我已经用?sap-ui-xx-nosync=warn检查了加载情况,并得到了以下结果:

enter image description here

由于某些原因i18n/i18n_en.properties被同步加载。我访问i18n的唯一位置是:

const oBundle = myI18nModel.getResourceBundle();

但是根据文档,我无法理解为什么myI18nModel.getResourceBundle()会导致同步加载。

更新#2:

在深入研究no sync XHR示例之后,我发现了sync XHR警告的原因。明确指出了"description": "{{appDescription}}"中的"title": "{{appTitle}}"manifest.json

"title": "Here the i18n bundles can't be loaded with 'async: true' yet!","description": "Same here. Hence,no 'i18n' in this 'sap.app' section!"

将其替换为静态值后,警告消失了。

解决方法

UI5的早期开发很大程度上基于synchronous XHRs。旧版应用程序或一些过时的文档主题可能仍指的是默认禁用异步选项无异步选项的API,例如:sap.ui.controllersap.ui.componentsap.ui.*fragmentsap.ui.*viewjQuery.sap.requiresap.ui.requireSyncjQuery.sap.sjaxComponentContainer的构造函数,如问题。

为了减少同步XHR呼叫的次数:

  1. 遵循已记录的准则:

    尤其是在引导时,请使用data-sap-ui-async="true"选项,如果应用程序具有Component.js,请使用use the declarative sap/ui/core/ComponentSupport module in data-sap-ui-oninit,而不是手动实例化sap.ui.core.ComponentContainer。例如:

    <head>
      <!-- ... -->
      <script id="sap-ui-bootstrap" ...
        data-sap-ui-async="true"
        data-sap-ui-oninit="module:sap/ui/core/ComponentSupport"
      ></script>
    </head>
    <body id="content" class="sapUiBody">
      <div data-sap-ui-component
        data-id="rootComponentContainer"
        data-name="demo"
        data-settings='{ "id": "rootComponent" }'
        ...
      ></div>
    </body>

    这会自动创建一个ComponentContainer,将其推送到DOM,并同时异步地加载Component.jsmanifest.json ,同时避免内联脚本或单独的引导程序脚本。

  1. 使用xx-nosync bootstrap option运行应用程序。例如,在URL中:

    https://<host>/my/awesome/app/?sap-ui-xx-nosync=warn

    UI5随后将在浏览器控制台中为同步获取的每个文件记录“正在加载...带有同步XHR” (忽略其他[nosync]消息)。例如:

    • 如果应用程序使用v2.ODataModel,则可能会抱怨模块sap/ui/thirdparty/datajs已同步加载。在这种情况下,请将以下内容添加到引导程序配置中:
      <script id="sap-ui-bootstrap" ...
        data-sap-ui-async="true"
        data-sap-ui-oninit="module:sap/ui/core/ComponentSupport"
        data-sap-ui-modules="sap/ui/thirdparty/datajs"
      ></script>
    • 如果在JS中手动创建了ResourceModel,请确保在其中启用async标志:
      const i18nModel = new ResourceModel({ // required by "sap/ui/model/resource/ResourceModel"
        bundleName: "demo.i18n.i18n",supportedLocales: [""],fallbackLocale: "",async: true,// <--
      });
      i18nModel.getResourceBundle().then(resourceBundle => {
        this.getOwnerComponent().setModel(i18nModel,"i18n");
        resourceBundle.getText(/*...*/); // See sap/base/i18n/ResourceBundle
      });

    检查所报告API的API参考。在大多数情况下,它们要么被弃用,要么默认将async标志设置为false

仍然有一些API,它们还没有异步替代品,例如:

  • 实例化sap/ui/core/LocaleData时使用同步XHR获取CLDR file(例如,用于Calendar或DatePicker。请参见Issue #2345)。
  • "{{...}}"中解析类似i18n Handlebar的manifest.json语法时

但是,使用最新的稳定版UI5,可以消除大多数同步请求。
这是一个没有同步XHR的示例:https://embed.plnkr.co/7txzTsNwOBDbyi87


要回答这个问题:sap.ui.definesap.ui.require会异步加载依赖项如果 data-sap-ui-async的配置设置为true {{3} }。另外,请确保(Replaces data-sap-ui-preload="async"),以防止出现主要的性能瓶颈。

不幸的是,用async-await / Promise包装同步内容请求不会有帮助。更好地寻找异步替代方案。例如,add dependent libs to the manifest.json在构造函数设置中具有async标志,如果启用了该标志,则异步获取Component.jsmanifest.json文件:

new ComponentContainer({
  height: "100%",name: "webapp",async: true,// or
  manifest: true,// sets the `async` option automatically to true
})
,

控制台中的同步jobs: printInputs: runs-on: ubuntu-latest steps: - run: | echo "Env: ${{ github.event.inputs.environment }}" echo "Branch: ${{ github.event.inputs.branch }}" 警告可能来自实际核心的剩余。我知道启动板在这方面存在一些问题。如果您安排时间或仔细查看“网络”标签/“源”标签,则会发现在加载您自己的代码之前已显示该消息。

XMLHttpRequest之类的文件中,或者在类似的地方,您会发现sap.jquery.js带有XMLHtppRequests标志集。我已经与UI5小组进行了讨论,并且正在将其删除,但没有提供时间表。

为了更直接地回答您的问题,sync部分是异步的。这个想法取自require js,至今已至少10年。

//编辑

require / async不会做任何事情,因为这些都不是基于承诺的。进行await只是假设窗口对象在加载控制器之前已附加了sap.m.Shell库,您可以确保例如通过清单自动加载。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-