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.


And I am trying to load it as below

<ltng:require styles="/resource/myResources/styles/styles.css" 
                  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

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" 
                  afterScriptsLoaded="{!c.setup}" />

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.