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}"/> 
  • Can you please provide the full code so I can try to reproduce? – nickforce Dec 4 '19 at 2:34
  • Do you see any errors in console for the case that's not working ? Have scripts been successfully loaded ? – Mohith Shrivastava Dec 4 '19 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 Kahn Dec 4 '19 at 2:56
1

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}" />
| improve this answer | |
  • Thanks @sfdcfox for your reply but unfortunately it does not work with your suggestion :( – Nick Kahn Dec 4 '19 at 17:53
  • @NickKahn Did you fix your file? – sfdcfox Dec 4 '19 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 Kahn Dec 4 '19 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 Kahn Dec 4 '19 at 19:02
  • @NickKahn What's in your zip file? – sfdcfox Dec 4 '19 at 19:29

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.