+ Start a Discussion
Daniel Rudman 5Daniel Rudman 5 

Accessing static resources in Lightning components

How do I access a ZIP static resource dynamically in a Lightning componenet? I tried the {!URLFOR()} notation but it is not supported. I want to import a style sheet.

Hi Daniel,
simply call like this:
<img src="/resource/ZIPPED_RESOURCE_NAME/afolder/afile.png" />
May the Force.com be with you!
Pavlo Cherkashyn 5Pavlo Cherkashyn 5
what if the public static resource zip is in different package?

neither /resource/ZIPPED_RESOURCE_NAME


nor /resource/package/ZIPPED_RESOURCE_NAME

worked for me so far. Any workarounds?
Sprouts FarmSprouts Farm
Below syntax could be referred :
<apex:stylesheet value="{!URLFOR($Resource.SLDS0120, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
This shoould do the trick: <ltng:require styles="/PATH_TO_RESOURCE" />

Anoop AmbookenAnoop Ambooken
Hi. when i was tryign to use a zip file and tried what Enreeco suggested below , it did not work 
<img src="/resource/ZIPPED_RESOURCE_NAME/afolder/afile.png" />

So i kind of used a cheat way. I uses the prebuilt zip file provided by salesforce in my components obtained from below link.
This zip file has folder called /asset/images . Place you .png or .jpg files inside this folder (eg: pic1.png). Similary if you have additional own style sheets and fonts, place in /assets/fonts and /assets/styles.

Now save the new zip and attach this zip as static resource. Now use the images like below  and it was workign for me. I essentialy used the prebuilt salesforce lightning zip package and tweaked it a bit, without need of compiling. This worked for me and let me know if there is a better way 
<img src="/resource/ZIPPED_RESOURCE_NAME/assets/images/pic1.png" />

Suresh tavva 10Suresh tavva 10
Hi Team,

Please use below link....