on ‎2019 Jul 08 6:10 PM
Hi,
I am changing the pre-load property in my index.html tag to ''async".
When I do that, I believe below code makes sure that my application or component.js file doesn't get loaded until all the required SAPUI5 libraries are loaded. If I am correct till now, may I know if sap.ui.getCore().attachInit() acts as a promise and only when this is resolved the callback function within the attachInit() will get executed ?
Again, if I am correct till now, then may I know where are we making sure that sap.m library and other SAPUI5 libraries are also loaded, as I only see attachInit for sap.ui library.
If I am completely off mark, please let me know how do we handle the async pre-load in SAPUI5 applications and how can we set the pre-load='async' property in application where index.html is not available.
<script>
sap.ui.getCore().attachInit(function() {
new sap.m.Shell({
app: new sap.ui.core.ComponentContainer({
height : "100%",
name : "com.sunSampleGetData"
})
}).placeAt("content");
});
</script>
Request clarification before answering.
providing async option will asynchronously load those modules you've provided in the sap-ui-libs, which means other requests will go even if those modules are not loaded yet. check the below blog:
https://blogs.sap.com/2016/10/29/sapui5-application-startup-performance-best-practices/
now the attahInit is not a promise but it is a function which will register your handler function and will call it once the core is loaded. it kinda behaves like a promise but it's definitely not a promise.
https://ui5.sap.com/#/api/sap.ui.core.Core/methods/attachInit
This function you've passed will be called once after the core is loaded successfully and this is independent of teh async option you provide as per my knowledge. BTW as per the latest ui5 standards, you are not supposed to do that and use the below:
https://ui5.sap.com/#/topic/1f81a093a9f3433983dcb2ebe11cd4cd
BR,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Mahesh. I have a follow up question.
Since index.html file is not used when application is accessed from FIORI launchpad, may I know where and how we can declare preload='async' ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Very good question, you don't need to. SAP fiori launchpad will take care of loading the initial resources and via async only for all Ur resources that u mention in manifest.json
What you can do is set to lazy load the libraries.
https://ui5.sap.com/#/topic/408b40efed3c416681e1bd8cdd8910d4
Using this means that libraries loaded when they are required.
Tip: you can click on comment on the answer and reply. We only need to answer if we have solution.
How this helps. Let us know if u need anything.
Br,
Mahesh
Thanks Saurabh. This helps. But on the other two questions I asked..
Can we consider sap.ui.getCore().attachInit(function() as kind of promise statement of java script ?
How are we making sure that the application is not waiting till all the SAPUI5 libraries are loaded ? Because, in the above code, we are only waiting for the sap.ui.core library to load but not the other sapui5 libraries like sap.m.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check Use Asynchronous Loading , the async property can be added to the manifest.json file as well. Also check the recommendations given here - Is Your Application Ready for Asynchronous Loading?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 13 | |
| 8 | |
| 7 | |
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.