Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load sapui5 resources in the background

Tags:

sapui5

In our application we load a number of SAPUI5 libraries. index.html has the following code to load the SAPUI5 resources

<script src="resources/sap-ui-cachebuster/sap-ui-core.js"
        id="sap-ui-bootstrap"
        data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.ux3,sap.m"
        data-sap-ui-theme="sap_bluecrystal" 
        data-sap-ui-appCacheBuster="./">

</script>

In our web.xml we have mentioned https://sapui5.hana.ondemand.com as the com.sap.ui5.resource.REMOTE_LOCATION to load the resources.

What we are observing is that the application takes a very long time to load for the first time. And network calls give an idea that loading of UI5 resources takes maximum time. Is there a way we can load the UI5 resources faster? or in the background? An advice or a code sample will really be helpful here. Thanks.

like image 302
Nitesh Agrawal Avatar asked Sep 01 '14 18:09

Nitesh Agrawal


People also ask

Which file will be loaded first when application loads in UI5?

The SAPUI5 Core gets loaded first and ensures a parallel loading of all required libraries. In addition, the browser loads all required CSS files in parallel.

What is SAPUI5 bootstrapping?

To use SAPUI5 features in your HTML page, you have to load and initialize the SAPUI5 library. You can use the SAPUI5 bootstrap script in your page to initialize SAPUI5 runtime automatically as soon as the script is loaded and executed by the browser.


2 Answers

You can load UI5 resources asynchronously. Use data-sap-ui-preload="async"

<script src="resources/sap-ui-cachebuster/sap-ui-core.js" id="sap-ui-bootstrap"
         data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.ux3,sap.m"
         data-sap-ui-theme="sap_bluecrystal" 
         data-sap-ui-preload="async"
         data-sap-ui-appCacheBuster="./">

But you must delay the access to the SAPUI5 APIs by using the attachInitEvent method

var oCore = sap.ui.getCore();
oCore.attachInit(function() {
    //do the needful
});
like image 67
Haojie Avatar answered Sep 28 '22 17:09

Haojie


You are trying to load too much at a time :sap.ui.commons,sap.ui.table,sap.ui.ux3,sap.m

Try to load only the essential parts and rest of the parts as async method so user can at least see some action before waiting too long:

Sync

 <script src="resources/sap-ui-cachebuster/sap-ui-core.js" id="sap-ui-bootstrap"
     data-sap-ui-libs="sap.ui.commons,sap.m"
     data-sap-ui-theme="sap_bluecrystal" 
     data-sap-ui-appCacheBuster="./">

ASYNC

 <script src="resources/sap-ui-cachebuster/sap-ui-core.js" id="sap-ui-bootstrap"
     data-sap-ui-libs="sap.ui.table,sap.ui.ux3"
     data-sap-ui-theme="sap_bluecrystal" 
     data-sap-ui-preload="async"
     data-sap-ui-appCacheBuster="./">
like image 40
Ank Avatar answered Sep 28 '22 15:09

Ank