docs

Best Practices for Developers

This page is a good starting point for you to ensure your code bases, specifically your OpenUI5 applications and libraries, are ready for the future and won’t become outdated.

On this page:


Best Practices for Legacy-Free Code

The OpenUI5 framework is always evolving to benefit from newer features in web browsers (like ECMAScript support) or to account for their end of maintenance (like the end of IE11 support). This is a continuous journey towards future major framework versions and improvements.

It is therefore important that you keep applying best practices. To help you, we frequently update the documentation in many places. This page collects fundamental information and offers practical guidance, and it will continue to evolve over time.

Note:

The following information is a preliminary yet practical collection of best practices to ensure legacy-free OpenUI5 development. We’re continuously improving it to reflect our latest recommendations. It will be further enhanced to both help transform existing code bases and provide guidance for creating new code.


Goals

The main objectives when migrating existing code or keeping it up to date with framework best practices are:


Prerequisites

Before attempting to migrate or upgrade to a higher OpenUI5 version, make sure that your development does not use any undocumented internal framework resources. Also, double check that all compatibility guidelines have been followed, such as those mentioned in Upgrading.

To build and serve your project in accordance with best practices, we recommend using the latest version of UI5 Tooling.


Supporting Tool - UI5 Linter

UI5 linter is a command-line tool to identify legacy code in your OpenUI5 project. It checks JavaScript, TypeScript, XML, JSON, and other files in your project and reports findings if legacy code is used. UI5 linter is our state-of-the-art tool to get and keep your OpenUI5 project legacy-free.


Deprecated APIs

In general, you must not use deprecated APIs anymore, such as sap.ui.getCore(). You can find deprecated APIs in the API Reference, in the What’s New Viewer, and in the reports by our Support Assistant and UI5 linter. For new projects, we recommend the use of TypeScript, because usage of deprecated APIs can then be detected easily.

Also, see the relevant warnings and errors logged to the browser’s dev console during runtime. You might need to increase the sap-ui-log-level. For more information, see Logging and Tracing.

Some APIs may be only partially deprecated, for instance passing a non-object vName to sap.ui.core.theming.Parameters.get. Refer to the API Reference for individual APIs. UI5 linter can also help detecting the deprecated usage of such APIs.

Using the native web API XMLHttpRequest#open with false as the third argument outside of workers is also deprecated, and browsers might end its support. Therefore, in addition to avoiding already deprecated OpenUI5 APIs, you must not call low-level APIs such as jQuery.ajax with a disabled async option either.

Additional Information:


Third-Party Libraries

Do not use any third-party libraries unless they are explicitly documented for usage by applications, for example in the Test Starter documentation. For more information, see Third-Party Open Source Libraries.

The integrated QUnit and Sinon libraries can be used via the Test Starter. Do not use the deprecated libraries QUnit 1 and Sinon 1.

Do not use jQuery APIs; use OpenUI5 APIs or native browser APIs instead.


Modules

Defining and Requiring Modules

For more information, see Best Practices for Loading Modules.

Requiring Third-Party Libraries

When requiring third-party libraries that export global names and support AMD at the same time, ensure having a shim with amd:true defined via sap.ui.loader.config beforehand. Use the required module value instead of the global name of the third-party library. For information on the usage of third-party libraries shipped with OpenUI5, see Third-Party Libraries.

Troubleshooting

Identify and resolve cyclic dependencies with the help of the OpenUI5 configuration parameter sap-ui-xx-debug-module-loading=true. Identified modules are logged in the browser console ([F12]) with the message ‘cycle detected’. Ensure that the console shows all levels of logs incl. “Verbose” ones to see this message.


App Development

In the following we’ll focus on crucial aspects of app development, specifically on asynchronous loading and best practices around Components, Controllers, Views, Fragments, Models, and ResourceBundles.


Asynchronous Loading

Additional Information:


OpenUI5 Object Creation

When creating instances of OpenUI5 controls programmatically (i.e. not declaratively via XML View or Fragment), then:

Additional Information:


Data Binding

Additional Information:


Standalone Apps

Additional Information:


Component / manifest.json

Component Creation

manifest.json

Dependency Management

Before using the Component’s EventBus instance via Component#getEventBus, define the sap/ui/core/EventBus as a dependency in your component controller (Component.js).

Bundling

Prevent bundling modules (Component-preload.js) into strings.


Controller / Views / Fragments

Additional Information:


Models

OData V4 Model

OData V2 Model

JSON Model

JSONModel#loadData: Do not pass false to the bAsync and bCache parameters, which are deprecated.

Additional Information:


Strict Error Handling

Implement strict error handling to address critical issues.


Control Development


Control Rendering

Additional Information:


Library Development


Library Dependency and Init

Additional Information:


Bundling

Prevent bundling modules (library-preload.js) into strings.


Testing