+ Start a Discussion
Shubham Sehgal 2Shubham Sehgal 2 

Loading Javascript using <ltng : require>

Hi All,

I am new Salesforce Lightning experience. I am trying to call an external JavaScript by loading it as a Static resource and calling it in my Lightning application using the following syntax but I am unable to get it work.

<aura:application >
       <ltng:require scripts="{!$Resource.SDFCTestJS}" afterScriptsLoaded="{!c.afterScriptsLoaded}"/>

Please suggest how can I get it work.

P.S : I read a solution that we can load Javascript by creating a Helper class and call it from our Component. Can anyone suggest a way so that I don't need to create helper everytime I call a component as I am going to have many; a way that I can include the JS directly from the above.

Thanks in advance.

Warm Regards,
Hello Shubham,

Try to use normal script tag instead of this.
<script src="{!$Resource.SDFCTestJS}" />
Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
Jasveer SinghJasveer Singh
   Shubham Sehgal 

use this code your problem is solve out

<ltng:require scripts="/resource/jq/"/>

where jq is the name of static resource upload in org.

if this is help full please mark the best

Thanks & Regards
Jasveer Singh
Jasveer SinghJasveer Singh
User-added image
Shubham Sehgal 2Shubham Sehgal 2

Thank youo for your response.

I tried using your code. Still not working. No error this time but nothing appears on the page.

Please suggest.

Jasveer SinghJasveer Singh
please follow this link i already post this type of answer

Jasveer SinghJasveer Singh
if your problem is solved out please you tell me

Thanks & Regards
Jasveer Singh
Rahul Kumar 151Rahul Kumar 151
<aura:application >
       <ltng:require scripts="/resource/jq/" afterScriptsLoaded="{!c.afterScriptsLoaded}"/>