Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I've uploaded the entire jQuery Mobile library, including the images the framework uses, as a single static resource on salesforce.

How can the JQM framework now refer to its images given their URL as static resources?

Are there good practices in this case?

share|improve this question

1 Answer 1

You need to make sure that the zip file name and the static resource name will be identical. And static res. name can contain only alphanumerics. I usually just cut the version references so later if I upgrade the library it I don't have to search & replace all occurrences. So rename the file to "jquerymobile" and upload it as resource with same name.

The official way

<apex:image id="loadingImg" 
 value="{!URLFOR($Resource.jquerymobile, 'jquery.mobile-1.2.0/images/ajax-loader.gif')}"/>

As you can see - URLFOR function takes extra parameter that's a subpath within the zip. Of course you probably won't be displaying images but CSS files - check <apex:stylesheet> tag.

The unofficial way

You can see what kind of file path was generated by examining the page source from the example above. In my case it's something like /resource/1354306153000/jquerymobile/jquery.mobile-1.2.0/images/ajax-loader.gif. The part with strange numbers is some kind of timestamp and funny enough - you can remove it ;)

<apex:image id="loadingImg" 
 value="/resource/jquerymobile/jquery.mobile-1.2.0/images/ajax-loader.gif"/>

(the unofficial way means you can use standard <img> tag if you want).

Regardless which one you choose - there will still be a hardcoded version number. It's your call now. I just repackage the zip with top directory renamed/completely removed so my static resources are really updating seamlessly. If you're afraid that stuff might get broken in future if you'll upload new version - leave it (and probably retain also the versioning in the zip/resource name).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.