What is the Function of aura:dependency?

Lightning (Aura) automatically detects dependencies (components, events, etc) when you reference something in markup (.cmp, .evt, .app, etc) but is blind to dynamic references in JavaScript. The end result is that dependencies that are detected end up with the component definitions (metadata) being included in the highly browser cacheable app.js/app.css resources. When a dynamic reference to something that is unknown client side is encountered Aura automatically faults to the server and calls a metadata service to get the def and then caches is in memory client side. This extra hop can make the first ref significantly more expensive and the fox is to add aura:dependency explicitly in the component that is doing the referencing.


Update as of several releases ago: Lightning/Aura detects a component's dependencies (components, events, interfaces, etc) referenced in markup and in Javascript (when the reference includes the markup:// prefix). When the component is fetched it'll include all of the necessary dependencies automatically. It is no longer required to use <aura:dependency> in the vast majority of cases.

<aura:dependency> should be used only advanced 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.