如何处理 bootstrap 的 data-sap-ui-libs 与 manifest 的 sap.ui5/dependencies/libs? [英] How to treat bootstrap's data-sap-ui-libs vs manifest's sap.ui5/dependencies/libs?

查看:35
本文介绍了如何处理 bootstrap 的 data-sap-ui-libs 与 manifest 的 sap.ui5/dependencies/libs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常在 sap.ui5/dependencies/libs 下的清单中声明应用程序依赖的所有标准库.

现在我应该在 bootstrap 参数 data-sap-ui-libs 中放什么,同样的库?如果我在 data-sap-ui-libs 中少放/多放会产生什么影响?它们有何不同?

附注.我在 SAP 的文档中找不到这个,但请证明我错了.:-)

解决方案

如果我在 data-sap-ui-libs 中少放/多放会产生什么影响?它们有何不同?

我的建议是从 index.html 中完全删除 data-sap-ui-libs.特别是,如果应用程序正在处理 OData,那么尽早检索 $metadata 文档很重要.请参见下面的示例:

index.html

<script id="sap-ui-bootstrap"src="https://ui5.sap.com/<version>/resources/sap-ui-core.js"data-sap-ui-theme="sap_fiori_3"data-sap-ui-oninit="module:sap/ui/core/ComponentSupport"数据-sap-ui-async="true"data-sap-ui-compatversion="edge"data-sap-ui-resourceroots='{演示":./"}'data-sap-ui-xx-waitfortheme="init"></script><!--  data-sap-ui-lib --><body id="content" class="sapUiBody"><div style="高度:100%"数据-sap-ui-组件数据名称=演示"数据高度="100%">

manifest.json

{sap.app":{数据源":{myODataSource":{uri":/odata_org/V2/Northwind/Northwind.svc/",类型":OData",设置":{odataVersion":2.0",localUri":model/metadata.xml",注释":[注释0"]}},注释0":{类型":ODataAnnotation",uri":annotation/annotation0.xml",设置":{localUri":annotation/annotation0.xml";}}},...},sap.ui5":{依赖关系":{minUI5Version":1.67.1",库":{sap.m":{},sap.ui.table":{},sap.ui.unified":{}}},模型":{":{数据源":myODataSource",设置":{preliminaryContext":真,令牌处理":假},预加载":真}},...},...}

结果

如您所见,$metadata 文档正在与控件库并行获取.这确保可以在加载库后立即请求实体(例如在 $batch 中).如果在 data-sap-ui-libs 中声明了库,它们将首先加载,然后$metadata和然后实体会造成不必要的瓶颈.

但即使不考虑 OData,我也注意到当从 data-sap-ui-libs 中删除库时,页面准备得更快.无论如何,我会尝试不同的方法并进行性能测量,除了遵循记录在案的性能指南之外,无论互联网上的人(包括我)怎么说.


TL;DR

  • 使用 data-sap-ui-libs 仅在以下情况下使用:

    1. 该应用根本没有 Component.js.
    2. sap.ui.core 之外的库中的模块在创建组件之前访问(例如实例化 sap.m.Shell 作为 ComponentContainer) 的外壳

  • 否则,完全删除 data-sap-ui-libs 并仅维护 sap.ui5/dependencies/libs - 特别是应该从应用容器启动,例如 Fiori Launchpad (FLP),它完全跳过加载 index.html.

I usually declare all standard libraries that the application depends on in the manifest under sap.ui5/dependencies/libs.

Now what should I put in the bootstrap argument data-sap-ui-libs, the same libraries? What are the effects if I put less / more in data-sap-ui-libs? How do they differ?

PS. I couldn't find this in SAP's documentation, but please proof me wrong. :-)

解决方案

What are the effects if I put less/more in data-sap-ui-libs? How do they differ?

My recommendation is to remove data-sap-ui-libs from index.html altogether. Especially if the app is dealing with OData, it's important to retrieve the $metadata document as early as possible. See the example below:

index.html

<head>
  <script id="sap-ui-bootstrap"
    src="https://ui5.sap.com/<version>/resources/sap-ui-core.js"
    data-sap-ui-theme="sap_fiori_3"
    data-sap-ui-oninit="module:sap/ui/core/ComponentSupport"
    data-sap-ui-async="true"
    data-sap-ui-compatversion="edge"
    data-sap-ui-resourceroots='{ "demo": "./" }'
    data-sap-ui-xx-waitfortheme="init"
  ></script><!-- No data-sap-ui-lib -->
</head>
<body id="content" class="sapUiBody">
  <div style="height: 100%"
    data-sap-ui-component
    data-name="demo" 
    data-height="100%"
  ></div>
</body>

manifest.json

{
  "sap.app": {
    "dataSources": {
      "myODataSource": {
        "uri": "/odata_org/V2/Northwind/Northwind.svc/",
        "type": "OData",
        "settings": {
          "odataVersion": "2.0",
          "localUri": "model/metadata.xml",
          "annotations": [
            "annotation0"
          ]
        }
      },
      "annotation0": {
        "type": "ODataAnnotation",
        "uri": "annotation/annotation0.xml",
        "settings": {
          "localUri": "annotation/annotation0.xml"
        }
      }
    },
    ...
  },
  "sap.ui5": {
    "dependencies": {
      "minUI5Version": "1.67.1",
      "libs": {
        "sap.m": {},
        "sap.ui.table": {},
        "sap.ui.unified": {}
      }
    },
    "models": {
      "": {
        "dataSource": "myODataSource",
        "settings": {
          "preliminaryContext": true,
          "tokenHandling": false
        },
        "preload": true
      }
    },
    ...
  },
  ...
}

Result

As you can see, the $metadata document is being fetched in parallel with the control libraries. This ensures that entities can be requested right away (e.g. in $batch) as soon as the libs are loaded. If libs were declared in data-sap-ui-libs, they'd be loading first, then the $metadata, and then the entities which creates an unnecessary bottleneck.

But even without considering OData, I noticed the page gets ready a bit faster when the libs are removed from data-sap-ui-libs. Anyhow, I'd try different approaches and do performance measurements, in addition to following documented performance guidelines, regardless of what people on the internet say (including me).


TL;DR

  • Use data-sap-ui-libs only if:

    1. The app has no Component.js at all.
    2. Modules from libraries other than sap.ui.core are accessed before creating the component (E.g. instantiating sap.m.Shell as a shell for the ComponentContainer)

  • Otherwise, remove data-sap-ui-libs altogether and maintain sap.ui5/dependencies/libs only - Especially if the app is supposed to be launched from an app container such as Fiori Launchpad (FLP) which skips loading index.html altogether.

这篇关于如何处理 bootstrap 的 data-sap-ui-libs 与 manifest 的 sap.ui5/dependencies/libs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆