In this tutorial we will be using load.cmp resource loader component to load CSS and JavaScript. We can use any other script loaders like requireJS as long as it is wrapped in a component.
Static Resources
Only way to load external scripts into Aura app is by first uploading them to Static Resources.
Static Resource Paths
- If the resource is not in a Zip file, you can access it by going to
<yourOrg>/resource/yourfile
(Note: there is no JS or CSS extension). - If the resource is inside a Zip file, you can access it by going to
<yourOrg>/resource/zipfileName/path/to/file.js
(note you need to provide file extension).
Upload static resources
This tutorial uses three files: a jquery
(jquery.js) file and a bootstrap.css
+ bootstrap.js
contained inside a zip file (aotp_bootstrap.zip).
Please follow the steps to upload both static resources.
- Download both of them.
- Setup > Develop > Static Resources
- Upload jquery.js file with name
jquery
- Upload aotp_bootstrap.zip with the resource name
aotp_bootstrap
Dependency ManamegementNote: In our example, bootstrap.js is actually dependent on jQuery. Thankfully load.cmp handles even dependencies in addition to loading either CSS or JS files.
Load load.cmp
Load load.cmp
own files manually
- Go to https://github.com/rajaraodv/loadcomponent
- Create
load.cmp
,loadController.js
andstaticResourcesLoaded.evt
files in your org - Copy-paste contents from each of those files.
- Change namespace from
jam
to your org’s namespace in all those files.
Manual loadingUnfortunately, at the time of writing this tutorial there is no tool to automatically upload components.