Lightning Components Performance Best Practices
(By Sunil Sharma and Arun Kumar)
- Listen to user events and other events like Component Event, Application Event in Javascript controller.
- Use helper methods to write your business logic.
- Do not trigger DML operation on component initialization. If you are doing DML in init(), you are creating a CSRF(Cross-Site Request Forgery).
- When making a call to the server, limit the columns and rows of the result. Use only the required column (fields). Do not return huge number of records in a single query make use of ‘LIMIT’.
- Do not modify DOM in Controller. If you modify DOM in Controller it will call renderer method which will end in no result.
- Cache data when possible.
- For Client-side filtering and sorting: Don’t make a call to the server to filter or sort data. This should be done at client side.
- Use Renderer whenever you want to customize default rendering, re-rendering, after rendering and unrendering behavior for a component.
- Do not fire an event in renderer as this can cause an infinite rendering loop.
- Limit the use of Application Events.
- Use <aura:if> when you need to conditionally render UI elements.
- It is a good practice to use events for communication between lightning components.
- Always try to use a component event instead of an application event, if possible.
- We should use application event for something that should be handled at the application level, such as navigation to specific record, list view, etc.
- It is a good practice to handle low-level events, such as a click, in your event handler and refine them as higher-level events, such as an approval change event or whatever is appropriate for your business logic.
- We should not use onclick and ontouchend event in a component. The lightning component framework translates touch-tap events into clicks and activates any onclick handler that are present in javascript controller or helper.
No comments:
Post a Comment