Performance 为什么SAPUI5多次加载类似的片段?

Performance 为什么SAPUI5多次加载类似的片段?,performance,caching,sapui5,sap-web-ide,sap-business-technology-platform,Performance,Caching,Sapui5,Sap Web Ide,Sap Business Technology Platform,我有一个XML片段,并在XML视图中的多个位置使用它 <IconTabFilter text="ABC" key="1" icon="sap-icon://alphabetical-order"> <content> <Table id="table1" width="auto" items="{path:'/ContactSet',parameters:{expand:'BusinessAddress,HomeAddress,OtherAd

我有一个XML片段,并在XML视图中的多个位置使用它

<IconTabFilter text="ABC" key="1" icon="sap-icon://alphabetical-order">
    <content>
        <Table id="table1" width="auto" items="{path:'/ContactSet',parameters:{expand:'BusinessAddress,HomeAddress,OtherAddress,Photo'},filters:[{path:'Surname',operator:'StartsWith',value1:'A'},{path:'Surname',operator:'StartsWith',value1:'B'},{path:'Surname',operator:'StartsWith',value1:'C'}]}" noDataText=" {worklistView>/tableNoDataText}" busyIndicatorDelay="{worklistView>/tableBusyDelay}" growing="true" growingScrollToLoad="true" updateFinished="onUpdateFinished">
            <headerToolbar>
                <core:Fragment fragmentName="de.cimt.cimply.AddressBook.view.worklist.tablesHeader" type="XML"/>
            </headerToolbar>
            <columns>
                <core:Fragment fragmentName="de.cimt.cimply.AddressBook.view.worklist.tablesColumns" type="XML"/>
            </columns>
            <items>
                <core:Fragment fragmentName="de.cimt.cimply.AddressBook.view.worklist.tablesRows" type="XML"/>
            </items>
        </Table>
    </content>
</IconTabFilter>
<IconTabSeparator icon="sap-icon://process"/>
<IconTabFilter text="DEF" key="2" icon="sap-icon://alphabetical-order">
    <content>
        <Table id="table2" width="auto" items="{path:'/ContactSet',parameters:{expand:'BusinessAddress,HomeAddress,OtherAddress,Photo'},filters:[{path:'Surname',operator:'StartsWith',value1:'D'},{path:'Surname',operator:'StartsWith',value1:'E'},{path:'Surname',operator:'StartsWith',value1:'F'}]}" noDataText="{worklistView>/tableNoDataText}" busyIndicatorDelay="{worklistView>/tableBusyDelay}" growing="true" growingScrollToLoad="true" updateFinished="onUpdateFinished">
            <headerToolbar>
                <core:Fragment fragmentName="de.cimt.cimply.AddressBook.view.worklist.tablesHeader" type="XML"/>
            </headerToolbar>
            <columns>
                <core:Fragment fragmentName="de.cimt.cimply.AddressBook.view.worklist.tablesColumns" type="XML"/>
            </columns>
            <items>
                <core:Fragment fragmentName="de.cimt.cimply.AddressBook.view.worklist.tablesRows" type="XML"/>
            </items>
        </Table>
    </content>
</IconTabFilter>

但是视图加载时间太长,尤其是在WEBIDE中

原因是它多次加载类似的片段文件。这是一个证据:

问题是如何提高性能?


我不想重复代码,我需要将这部分代码放在一个片段中,但我希望我的浏览器不会多次加载同一个文件。

如果你不在webide测试环境中运行你的应用程序,那么应该从缓存中加载片段

但是,您可以将片段加载到控制器中,并使用factoryfunctions而不是模板。比如:

视图:

片段:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
<StandardListItem icon="sap-icon://warning" title="{Name}" />


在这种情况下,无需更改代码。SAP Web IDE/SCP利用了开箱即用的概念,只要这些资源以前没有被更改,就可以从浏览器缓存中获取应用程序资源(例如片段)

请参见下面的示例屏幕截图:

鉴于
  • 代码:

    
    
  • URL属性
    sap ui appCacheBuster=…
    哪个Web IDE在应用程序启动时自动附加(描述
    sap ui cachebuster info.json
    的位置)

  • 如果devtool处于打开状态:禁用缓存未选中我将尝试,但您可以用一些代码支持您的答案,如果可行的话,我可以选择它作为正确答案。只有当我们直接使用
    时,它才有帮助。在某些情况下,如SmartTable,它不是那么有用的解决方案。SmartControls的操作非常有限!但是,您可以尝试添加占位符视觉效果,并在渲染后将其替换为片段。但这并不是一个很好的解决方案ps:除了上面的答案之外,请注意片段仍然是通过sync XHR加载的,即使使用,这会显著降低页面加载速度(如果禁用从缓存加载)。但是应该修复:我是否正确理解
    Application Cache Buster
    AppCacheBuster
    )仅与具有SAP后端的应用程序相关,并且在所有其他情况下(例如Node.js后端,
    AppCacheBuster
    )不相关?
        onInit: function () {
    
            this.getView().setModel(new JSONModel({
                "myList" : [{
                    "Name": "Test1"
                }, {
                    "Name": "Test2"
                }]
            }));
    
    
        },
    
        myListFactory: function (sId) {
            if(!this._myListFragment){
                this._myListFragment = new sap.ui.xmlfragment("test.test.view.myListFragment", this);
            }
            return this._myListFragment.clone(sId);
        }
    
    <core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
    <StandardListItem icon="sap-icon://warning" title="{Name}" />