I am able to include a JS file as static resource in my lightning component. But when I add "<<'script'>>" tag in the JS file it gives an error.

I want script tag as i need to use src attribute in the JS file and then call it through static resource in my lightning component

JS Code

  • Welcome to the SE community it is always better to post your existing code while asking the question. it will avoid extra conversation and you will get specific answer in timely manner. You can go through the help section to understand how to ask a good question. – Himanshu Nov 3 '15 at 17:45

script tag is not supported into in lightning component so you need to use ltng:require to include script from static resource in following way

<ltng:require scripts='/resource/path/to/js1.js,/resource/path/to/js2.js'/>

Note: SFDC don't allow to put inline script tag so only option is to move javascript code insdie controller.js or load from external javascript as shown above.

  • Yes I used the above code and included the JS file , In the JS file i need to add script src = "my code" – Nikx Nov 3 '15 at 17:43
  • do you see any error? post your lightning component code here. – Himanshu Nov 3 '15 at 17:43
  • Syntax error for "<" Basically it doesnt allow script tag in JS file – Nikx Nov 3 '15 at 17:44
  • update this question with your complete component code. I am not getting what you are referring here. – Himanshu Nov 3 '15 at 17:46
  • <aura:application> <ltng:require scripts="/resource/Test" /> </aura:application> JS Code <script src="//test.com/test.js"></script> – Nikx Nov 3 '15 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.