Loading
Important Advisory: iOS Update Impacting CG Mobile ApplicationRead More
Extend Salesforce with Clicks, Not Code
Configure Site Caching

Configure Site Caching

Caching your Salesforce Site pages, attachments, and static resources can improve page load times and site performance. It can also help you avoid reaching bandwidth and service request time limits.

Required Editions

Available in: both Salesforce Classic and Lightning Experience
Available in: Developer, Enterprise, Performance, and Unlimited Editions

To optimize content delivery to your end users, you can enable or disable caching and set the cache duration for each of your site’s pages, attachments, and static resources.

Caching Behavior for Static Site Resources

Static site resources such as images, style sheets, and scripts are cached based on the Cache Control attribute on the resource. For more information, see Define Static Resources in Salesforce Help.

Caching Behavior for Attachments

For attachments stored in Experience Cloud sites and Salesforce Sites, the caching behavior varies based on the type of attachment.

Attachment Type Caching Behavior Caching Location
Documents and attachments The cache expires according to maxage parameter, in seconds. For example: /servlet/servlet.FileDownload?file=<FileID>&maxage=600 End user’s web browser
Images in a rich text area The cache expires in 45 days.

Unauthenticated guest users without IP restrictions: Proxy server

Guest users with IP restrictions and authenticated users: end user’s web browser

Site-Level Caching Option for Public Visualforce Pages

To control whether a site’s public Visualforce pages are cached, set the site-level setting Cache public Visualforce pages. This setting is enabled by default for new sites.

When that site-level setting is enabled:

  • Proxy servers cache the publicly accessible Visualforce page responses only during page visits by unauthenticated guest users.
  • The caching behavior and caching location for publicly accessible Visualforce pages differ based upon whether IP range restrictions or login hours restrictions are defined for the site's guest user.
  • If caching occurs at the network level, when a page is cacheable for guest users, an unauthenticated version of that page can be served to authenticated users. Examples of options that can cache your site pages at the network level include content delivery networks (CDNs) and intercepting proxy servers, such as a data loss prevention (DLP) proxy. This behavior can also occur when a custom domain uses the Salesforce CDN or your HTTPS certificate to serve your site.
  • You can disable caching for an individual publicly accessible Visualforce page. To disable that caching, set the page’s boolean cache attribute to false.

When the site-level setting is disabled:

  • The proxy server doesn’t cache any of the site’s Visualforce pages. Instead, the site’s cache-enabled Visualforce pages are cached in the web browser for both authenticated and unauthenticated users. This caching behavior matches caching for Visualforce pages served by Salesforce outside of a site.
  • You can enable caching for an individual publicly accessible Visualforce page. To enable that caching, set the page’s boolean cache attribute to true.

Page-Level Caching Options for Public Visualforce Pages

To control the caching behavior for your site’s Visualforce pages, set the boolean cache attribute and the integer expires attribute on each page.

For example, a Visualforce page whose cache is set to expire in 15 minutes looks like this:

<apex:page cache="true" expires="900">

Caching Behavior for Visualforce Pages When Site-Level Caching Is Enabled

Here are the rules for caching when the site-level Cache public Visualforce pages setting is enabled.

  • The page is cached only when the page-level cache attribute is true or when that attribute isn’t set.
  • The caching behavior and location also differ based upon whether IP range restrictions or login hours restrictions are defined for the site's guest user.
  • When caching occurs in these cases, the cache expires based on the page's expires attribute. If the page’s expires attribute isn’t set, the cache expires in 600 seconds (10 minutes).
Event Page-Level cache Attribute Site Guest User Restrictions Caching Location
An unauthenticated user visits a login-enabled site. true, false, or not set Yes Not cached
true or not set No Proxy server and end user’s web browser
false No Not cached
An authenticated user visits a login-enabled site. true, false, or not set Yes or No Not cached
A user visits a Salesforce Site that isn’t login-enabled. true or not set Yes End user’s web browser
No Proxy server and end user’s web browser
false Yes or No Not cached

Caching Behavior for Visualforce Pages When Site-Level Caching Is Disabled

When the site-level Cache public Visualforce pages setting is disabled, you can enable caching for specific pages via the page-level cache attribute. When that attribute is true, the Visualforce page is cached in the end user's web browser and the cache expires according to the page’s expires attribute. If the page’s expires attribute isn’t set, the cache expires in 0 seconds.

This behavior applies to both authenticated and unauthenticated users regardless of whether the site is login-enabled. Also, the presence of IP range restrictions or work hour restrictions on the site’s guest user has no impact on this caching behavior.

Event Page-Level cache Attribute Caching Location
A user visits a site. true End user’s web browser
false or not set Not cached
 
Loading
Salesforce Help | Article