Find your content:

Search form

You are here

Visualforce + jQuery Mobile Images as Static Resource


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?

Attribution to: jmrjulian

Possible Suggestion/Solution #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, '')}"/>

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/ The part with strange numbers is some kind of timestamp and funny enough - you can remove it ;)

<apex:image id="loadingImg" 

(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).

Attribution to: eyescream
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content