3

I have created a folder name myResources. It has two sub folders styles and scripts. scripts folder has two files js1.js and js2.js. styles folder has one file styles.css.

myResources->scripts->js1.js
myResources->scripts->js2.js
myResources->styles->styles.css

And I am trying to load it as below

<ltng:require styles="/resource/myResources/styles/styles.css" 
                  scripts='/resource/myResources/scripts/js1.js,
                          /resource/myResources/scripts/js2.js' 
                  afterScriptsLoaded="{!c.setup}" />  

I have also tried

<ltng:require styles="{!$Resource.myResources+ '/styles/styles.css'}" />
<ltng:require scripts="{!join(',', 
                           $Resource.myResources+ '/scripts/js1.js', 
                           $Resource.myResources+ '/scripts/js2.js')}" 
                  afterScriptsLoaded="{!c.setup}" />  

But not luck so far, I don't know what I am doing wrong.
My static resource name is myResources.
Note: I have upload them individual files not .zip file It loads successfully.
Following this tutorial Loading External JavaScript And CSS Libraries To Lightning Components

  • Are you sure you named your static resource "resource" ? – Martin Lezer Feb 2 '17 at 10:59
  • yes I am sure it is myResources I can see in setup->static resource . It has name is myResources and type application/octet-stream – ozil Feb 2 '17 at 11:02
4

Since your folder name and static resource name both are myResources, its leading upto a confusion.

You need to include your folder name as well in the path like this.

<ltng:require styles="/resource/myResources/myResources/styles/styles.css" 
                  scripts='/resource/myResources/myResources/scripts/js1.js,
                          /resource/myResources/myResources/scripts/js2.js' 
                  afterScriptsLoaded="{!c.setup}" />
|improve this answer|||||

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.