Co-Authored By:
Asked by: Hachim Obolensky
technology and computing web developmentHow do I use an external JavaScript in a lightning component?
Following steps are used to load the external Java Script library in lightning component.
- Load your external java script library in static resource. Goto >> SetUp>> Custom Code >> Static Resources.
- Use <ltng:require> tag to load the Java Script library in lightnig component as follows. <!-- For one js library --> <!--
Also to know is, what is a capability of the Itng require tag that is used for loading external JavaScript libraries in lightning components?
ltng:require enables you to load external CSS and JavaScript libraries after you upload them as static resources. Due to a quirk in the way $Resource is parsed in expressions, use the join operator to include multiple $Resource references in a single attribute.
Also, how is CDN used in lightning component?
To enable the CDN:
- From Setup, enter Session in the Quick Find box, and then select Session Settings.
- Select the checkbox for “Enable Content Delivery Network (CDN) for Lightning Component framework”.
- Click Save.
Save the JS file on your computer.
- Step 2 : Upload Data Table zip file + jQuery js file as a static resources in your Salesforce org.
- Step 3 : Use jQuery Data Table on salesforce lightning component.
- Step 4 : Create Apex Controller.
- Step 5 : Create Lightning Component.