We’ve a requirement to display a few images on a Visualforce page.
In the current setup, we’ve each of these images stored in individual static resources. The image names are stored in a custom object to facilitate dynamic rendering of images on the Visualforce page. The controller pulls the relevant image name for the logged in user from the custom object, and uses the below markup to display the image on the page.
<apex:image url=“/resource/{!imageName}” />
We want to move to the recommended approach of using $Resource.imageName as a merge field, but have challenges there as the image name has to come from the controller. So we’re thinking of combining all the images into one zip file. This way we’ve two birds in one shot, fewer static resources to manage and can proudly say we follow the "recommended approach” in coding. 😃
But before doing that, we’ve a couple of questions that we cannot seem to find an answer for:
1. Why $Resource?
What are the advantages of using the merge field against the URL, other than being the recommended approach? It seems like when we’re using the URL approach, Salesforce is intelligent enough to serve the correct resource even after an update changed the timestamp on the resource.
2. URL Approach - with or without timestamp?
As mentioned earlier, the current implementation works fine now. But as per documentation, it should be <apex:image url=“/resource/<timestamp>/{!imageName}” />
instead. What is the relevance of the timestamp component of the URL? What are the impacts of excluding this timestamp?
Wondering what the experts here thinks about these.