I'm confused when to use <aura:dependency resource="force.."> and when not?

If my component is using on of the following system events does it need to be explicitly declared as dependency?

  • force:closeQuickAction
  • force:createRecord
  • force:navigateToSObject
  • force:showToast
  • ...

I remember having read that system events are somewhat autodiscovered but in some open source repos (e.g. Strike Components) I found components declaring them explicitly.

  • That's an interesting question, I thought using aura:registerEvent was doing this dependency job. – Fabien Taillon Jun 6 '17 at 8:04
  • As I understand the docs and code examples out there aura:registerEvent is only for custom events your components might trigger. Compared to java registerEvent is throws and dependency is catch. – Robert Sösemann Jun 6 '17 at 9:03
  • Isn't catch aura:handler ? To me aura:dependency was just for performance purpose, to be sure the definition of the event/component is sent to the browser. – Fabien Taillon Jun 6 '17 at 9:11
  • 1
    The only time I have ever needed to declare them was when using Lightning Out. That is not to say it is the only time it is needed (I have not come close to any advanced use cases AFAIK) but with straight lightning it seems to know what is required without declaring a dependency – Eric Jun 7 '17 at 2:37

The system automatically detects a component's dependencies through several mechanism and ensures they're available on the client when it needs them.

<aura:dependency> is for advanced use cases where you need explicit control over prefetching of definitions. Using this effectively requires careful consideration and performance analysis.

I highly recommend not using them until you have a clear data-based need to control definition prefetching.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.