1

Let's say we don't want to use visual force page at this case.

I want to show the static resource in a external site.

Let's say filename: me.png

however, user will keep updating this file. Then, how could we avoid the caching problem.

For example: https://na53.lightning.force.com/me.png

I believe this will cause the cached issue and also we have no way to get the timestamp for fetching this image.

How could we solve the problem?

closed as off-topic by Eric, glls, David Reed, Himanshu, battery.cord Aug 6 '18 at 13:25

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – David Reed, battery.cord
  • "Programming questions not specific to Salesforce are off-topic here, but can be asked on Stack Overflow." – Eric, glls, Himanshu
If this question can be reworded to fit the rules in the help center, please edit the question.

3

The URL of a static resource automatically includes the timestamp when it was last updated providing you access it via $Resource (and similarly $Resource for Lightning) and this ensures that the static resource is re-cached at the client-side when it changes.

Use this mechanism in your logic.

If you can't go via Visualforce, you can create the equivalent URL yourself via querying the static resource's LastModifiedDate:

        for (StaticResource sr : [
                    select LastModifiedDate
                    from StaticResource
                    where Name = :name
                    order by CreatedDate desc
                    limit 1
                    ]) {
            return '/resource/' + sr.LastModifiedDate.getTime() + '/' + name;
        }

Or if no caching at all is OK, you can just insert the numerical value of now in the URL and that will route to the latest version. (As may having no timestamp at all - use your browser's "Network" tab from its "Developer Tools" to check.)

  • this solution works out. We did put Time.now() for fetching the latest statis resource, many thanks! – Dummy Aug 6 '18 at 17:19

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