Activity Forums Salesforce® Discussions How do I include external JavaScript libraries in Salesforce lightning components?

  • Avnish Yadav

    Member
    July 17, 2018 at 5:50 am

    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

  • Parul

    Member
    September 15, 2018 at 7:21 am

    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.

  • shariq

    Member
    September 15, 2018 at 6:24 pm

    Hi,

    Try this -

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

    Hope this helps.

  • Parul

    Member
    September 28, 2018 at 6:00 pm

    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.

Popular Salesforce Blogs