Preload sap.ui.unified.Calendar

2019-07-27 23:29发布

问题:

I'm testing my UI5 application's performance on a slow 3G connection. I've noticed that it takes quite some time to load the sap.ui.unified.Calendar for the first time when using the sap.m.DateTimePicker.

This is mentioned in the official documentation. The proposed solution is to preload the sap.ui.unified library. I have tried multiple ways of doing this but regardless of what I do, the Calendar still takes long to load the first time.

  • I have tried adding sap.ui.unified to data-sap-ui-libs in my index.html.
  • I have tried using jQuery.sap.require("sap.ui.unified") (which is apparently deprecated).
  • I have tried using sap.ui.require(["sap/ui/unified/Calendar"]).

None of these solutions work. Any help would be appreciated.


UPDATE

The DateTimePicker is declared as follows in an XML View:

<DateTimePicker
    id="dtClockIn"
    valueFormat="MM-dd-YYYY hh:mm a"
    displayFormat="MM-dd-YYYY hh:mm a"
    placeholder="MM-DD-YYYY hh:mm ampm"/>

There's nothing fancy happening in the controller.

回答1:

1.50 and below

Currently, library resource bundles (messagebundle*.properties files) are loaded on-demand and synchronously which creates a bottleneck before making use of the corresponding control (e.g. Calendar). I'm afraid we can't do much about it.

You could, however, at least prefetch the bundle file by calling getLibraryResourceBundle manually when the UI is ready. E.g. on afterShow:

onAfterShow: function() {
  sap.ui.getCore().getLibraryResourceBundle("sap.ui.unified");
  // Avoids fetching it later when the Calendar is about to be shown
},

As of 1.52

With v1.52, such bundles are loaded beforehand asynchronously as long as libraries are configured to be loaded asynchronously. Here is an example: https://output.jsbin.com/qolesuf



标签: sapui5