Activity › Forums › Salesforce® Discussions › How do I include external JavaScript libraries in Salesforce lightning components?
-
How do I include external JavaScript libraries in Salesforce lightning components?
Posted by chanchal kumar on July 16, 2018 at 1:40 PMHow do I include external JavaScript libraries in Salesforce lightning components?
Parul replied 7 years, 7 months ago 4 Members · 4 Replies -
4 Replies
-
Hello Chanchal,
You want to include external javascript library, i suggest you to go with static resources , upload your javascript resources and use in your components.
Thanks
- [adinserter block='9']
-
I include external JavaScript libraries in Salesforce lightning components by following these steps:
1. Load your external java script library in static resource. Goto >> SetUp>> Custom Code >> Static Resources
2. Use <ltng:require> tag to load the Java Script library in lightnig component as follows.
Thanks.
-
Hi,
Try this –
<ltng:require scripts=”{!$Resource.resourceName}”
afterScriptsLoaded=”{!c.afterScriptsLoaded}” />Hope this helps.
-
Adding some points:
Reference a JavaScript library that you’ve uploaded as a static resource, use a <ltng:require> tag in your .cmp or .app markup.
The framework’s content security policy mandates that external JavaScript libraries must be uploaded to Salesforce static resources. For more information on static resources, see “Static Resources” in the Salesforce online help.Here’s an example of using <ltng:require>.
<ltng:require scripts=”{!$Resource.resourceName}”
afterScriptsLoaded=”{!c.afterScriptsLoaded}” />hope this helps you!
Log In to reply.