16

While creating a static resource there is an option for specifying Cache Control, This contains two values Public and Private. enter image description here

What does these values actually control?.

Initially had an Idea that if its public, it can be refered from outside salesforce.

2 Answers 2

17

From the docs:

Private specifies that the static resource data cached on the Salesforce server shouldn’t be shared with other users. The static resource is only stored in cache for the current user’s session.

Note Cache settings on static resources are set to private when accessed via a Force.com site whose guest user's profile has restrictions based on IP range or login hours. Sites with guest user profile restrictions cache static resources only within the browser. Also, if a previously unrestricted site becomes restricted, it can take up to 45 days for the static resources to expire from the Salesforce cache and any intermediate caches.

Public specifies that the static resource data cached on the Salesforce server be shared with other users in your organization for faster load times.

There's a good article on static resources and Visualforce on the developerforce wiki at:

http://wiki.developerforce.com/page/Delivering_Static_Resources_with_Visualforce

15

To distill the docs down:

  • using either, you'll never suffer from a stale cache so long as you use the URLFOR() function, which busts the cache with a timestamp whenever you update the static resource

Public resources:

  • will be accessible from a public-facing Force.com Site

Private resources:

  • require you to be authenticated with a Session Id (eg, in the org, in a portal, logged into a Site)

The rest of the details are behind the scenes :-)

1
  • 3
    thanks! and in my use case, using a Static Resource with cache control = private on an SSO-controlled Sites page results in a 401 (not found). Took me the longest time to realize this as same static resource cache control = private loaded just fine on a non-sites Page.
    – cropredy
    Commented Mar 28, 2016 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .