function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CuriosityCuriosity 

Is there any way to declare the sequence in which Lightning Components are initialized during page load?

What is the order of initialization of Lightning components?
I am building a Customer Community using the Napili Template. I have customized the home page by adding a few custom-built Lightning Components. I want to ensure that all the external JavaScript libraries are loaded last (lazy loading) so that the end-user does not have to stare at a blank page while all those libraries get loaded. For this I thought putting the <ltng:require> tags in my footer will work because I assumed that the components are initialized in order from top to bottom of the page and the Footer will initialize (i.e. fire the init event) all last since I had placed it at the very bottom of the page BUT in practice I am observing that many times the footer initializes before the other components do.
 
Ismael SlimaneIsmael Slimane
Hi! I have the same issue, did you find any solution? Thanks!
Ravi Dutt SharmaRavi Dutt Sharma
Put the entire component inside an aura:if tag. Initially keep the value of the variable used in aura:if as false.
 For including scripts use ltng:require

<ltng:require styles="" 
                  scripts="{}" afterScriptsLoaded="{!c.scriptsLoaded}"/>

In the afterScriptsLoaded method, change the variable used in aura:if to true.

Hope this helps.
S_RathS_Rath
You can use the lightning: spinner so that it will give a good look and feel to your components.

We know js executes the code asynchronously so we cannot judge which method will execute first.

So you can also add the code of doInit(Handler) in the method which you use in afterScriptLoaded if you want that your page get loads after the script.

Hope, this will help you in solving the issue.

Thanks