Performance Best Practices for Lightning Component Development
Single record : Lightning Data Service
Lightning Data Service を使用すると、Apex コードを必要とせずに、コンポーネントでレコードの読み込み、作成、編集、削除ができます。Lightning データサービスは、共有ルールと項目レベルセキュリティを処理します。Salesforce データへのアクセスを簡素化するだけでなく、Lightning データサービスはパフォーマンスとユーザインターフェースの一貫性を改善します。
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
<aura:attribute name="recordId" type="String" />
<lightning:recordForm recordId="{!v.recordId}"
objectApiName="Account"
mode="readonly"
fields="Name, Industry" />

Collections of records,custom data structures : Storable Actions
アクションを保存可能 (キャッシュ可能) としてマークすると、サーバとの往復を待たずにクライアント側ストレージのキャッシュデータをすばやく表示できるようになり、コンポーネントのパフォーマンスが向上します。
API バージョン 44.0 以上のコンポーネントの Apex メソッドから返されるデータをキャッシュするには、Apex メソッドに @AuraEnabled(cacheable=true) アノテーションを付加する必要があります
@AuraEnabled(cacheable=true)
public static Account getAccount(Id accountId) {
// your code here
}
Complete control over caching implementation : Custom cache
静的リソースに追加する
window.counter = (function(){
var Cache= {}; // private
return { //public API
setDate: function(name, data) {
Cache[name] = data;
},
getData: function(name) {
return Cache[name];
}
};
}());
afterScriptLoaded : function(component, event, helper){
var sectors = window.DataCache.getFata("sectors");
if(sectors){
component.set("v.sectors", sectors);
}else{
helper.loadSectors(component);
}
}
浙公网安备 33010602011771号