$A.createComponent() for lazy loading

If you have too many aura:if statements inside aura:iteration, you can transfer some logic to the controller to create markups conditionally using the $A.createComponents() API. The code snippet for this technique is shown, and, depending on the conditions, you can build the final component markup. Let's take a look at the code:

$A.createComponent(componentName, options, function(comp) {    var body = component.get("v.body");    body.push(comp);    component.set("v.body",cmp);});

This method reduces the number of components and improves performance. However, you are still using the framework, and there is some rendering cost consumed from the framework.

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.