I am working on a lightning component where I want to load resources then, an action function, then resources, then action function. I currently have the component set up like this:
<ltng:require styles="{!join(',',
$Resource.bootstrap3 + '/css/bootstrap.min.css',
$Resource.customCSS,
$Resource.lightgallery + '/lightgallery/css/lightgallery.css',
$Resource.SLDS100 + '/assets/styles/salesforce-lightning-design-system-vf.css')}"
afterScriptsLoaded="{!c.loadSfEnv}"/>
<!-- 60 lines of html -->
<ltng:require scripts="{!$Resource.myCustomAppBundle_js}"
afterScriptsLoaded="{!c.loadCustomApp}"/>
The c.loadSfEnv has an apex callback in it that gets data needed in the $Resource.myCustomAppBundle_js, which loads code needed in the c.loadCustomApp. The c.loadCustomApp action function also has apex calls in it and so its javascript can't be added to the $Resource.myCustomAppBundle_js. Most of the time the way of doing it above works because because the c.loadSfEnv callback is finished before $Resource.myCustomAppBundle_js loads but occasionally it doesn't load it in time and the page breaks.
Is there a way to ensure that $Resource.myCustomAppBundle_js is loaded only after the callback in c.loadSfEnv has completed? I've tried things like this below but it doesn't work.
<ltng:require scripts="{!join(',',
c.loadSfEnv,
$Resource.formDisplayAppBundle_js)}"
afterScriptsLoaded="{!c.loadForm}"/>
Update: An alternate solution would be to load the $Resource.formDisplayAppBundle_js in the callback of the c.loadSfEnv but I didn't know if that was possible.
ltng:requireand callc.loadSfEnvthen call helper'sloadCustomApp()method?