2

I uploaded my zip file which contains css and js folder here is my zip folder structure:

static resource name: mystaticresources

myuploadzip.zip 
     --js
         jquery211.js
         myjs1.js
     --css
         mycss.css

Aura component:

<ltng:require 
          styles="{!$Resource.mystaticresources + '/myuploadzip/css/mycss.css'}" 
 scripts="{!join(',', 
          $Resource.mystaticresources + '/myuploadzip/js/jquery211.js', 
          $Resource.mystaticresources + '/myuploadzip/js/myjs1.js')}"                  
 afterScriptsLoaded="{!c.doInit}" />

Controller:

 doInit: function(component, event, helper) {
        jQuery("document").ready(function(){
          alert('loaded');

      });
    },

I could not able to see what is wrong with the above code? I'm not getting alert!

I have jquery upload as a file without zip file and I have this reference in my component then it works:

 <ltng:require scripts="{!$Resource.jquery211}" afterScriptsLoaded="{!c.doInit1}"/> 
3
  • Can you please provide the full code so I can try to reproduce?
    – nickforce
    Commented Dec 4, 2019 at 2:34
  • Do you see any errors in console for the case that's not working ? Have scripts been successfully loaded ? Commented Dec 4, 2019 at 2:47
  • I started seeing the error now net::ERR_ABORTED 404 (Not Found) and trying to fetch from https://myawesome-dev-ed.lightning.force.com/resource/1575229828000/mystaticresources/myuploadzip/js/jquery211.js hmmm i'm not sure why i'm getting 404
    – Nick
    Commented Dec 4, 2019 at 2:56

1 Answer 1

2

ZIP Inside ZIP

If you have a ZIP inside the ZIP, this will fail. You can't access the resources inside of that file, as the system won't repeatedly/recursively decompress files this way.

You can verify this by downloading the static resource itself in your browser:

https://myawesome-dev-ed.lightning.force.com/resource/1575229828000/mystaticresources/

If the first entry you see is a ZIP file, your static resource won't work the way you expect. To fix this, ZIP the files you want into a ZIP, but do not ZIP that ZIP.

Normal ZIP Without Internal ZIP

The name of the ZIP isn't included in the file path; simply start from the js and css folders:

<ltng:require 
          styles="{!$Resource.mystaticresources + '/css/mycss.css'}" 
 scripts="{!join(',', 
          $Resource.mystaticresources + '/js/jquery211.js', 
          $Resource.mystaticresources + '/js/myjs1.js')}"                  
 afterScriptsLoaded="{!c.doInit}" />
9
  • Thanks @sfdcfox for your reply but unfortunately it does not work with your suggestion :(
    – Nick
    Commented Dec 4, 2019 at 17:53
  • @NickKahn Did you fix your file?
    – sfdcfox
    Commented Dec 4, 2019 at 18:57
  • I don't have zip inside zip, I have posted the structure of my zip folder in my question so I have a zip file within that zip file I have two folders.
    – Nick
    Commented Dec 4, 2019 at 19:00
  • so if I open a new browser and try to access this page https://myawesome-dev-ed.lightning.force.com/resource/1575229828000/mystaticresources I do get the zip file downloaded but when I try to do https://myawesome-dev-ed.lightning.force.com/resource/1575229828000/mystaticresources/js/jquery211.js I get 404
    – Nick
    Commented Dec 4, 2019 at 19:02
  • @NickKahn What's in your zip file?
    – sfdcfox
    Commented Dec 4, 2019 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .