5

This is more of just a general curiosity question, but I wanted to know which will fire or complete first. I have set up console.log() in each one but haven't been able to verify anything from that.

  <ltng:require scripts="{!$Resource.MomentJs}" afterScriptsLoaded="{!c.afterScriptsLoaded}" />
  <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

This is an example of what I'm using, the resource being Moment.js and the doInit function is simply console logging "init" in the controller.

1

1 Answer 1

10

aura:init always runs first, as it runs the moment the component is constructed via $A.createComponent/$A.createComponents (or the internal library equivalent), even before it exists in the DOM. All other events, including aura:render, aura:wait, aura:afterRender, and so on fire later in the life cycle.

4
  • awesome, just found a developer document on it, but your answer has a much more in depth explanation. Thanks
    – MMeadows
    Commented Dec 26, 2017 at 16:34
  • @MikeMeadows The docs are mostly correct, but even with a 150Mbps connection, I've never seen an afterScriptsLoaded end up going before an init, in practice.
    – sfdcfox
    Commented Dec 26, 2017 at 16:40
  • So there's no way to load an external library for use in the init event then? Commented Jun 8, 2018 at 17:11
  • @ScottMorrison I don't know what you're trying to do, but as far as I'm aware, it's likely impossible. You might want to ask a separate question with code so we can see what you're talking about.
    – sfdcfox
    Commented Jun 8, 2018 at 17:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .