HTTP Caching for Custom Components

Salesforce caches the latest version of a component with an HTTP cache using a time to live (TTL) of 5 minutes, or up to 10 minutes with the stale-while-revalidate directive. HTTP caching of your components means that your code changes can take up to 10 minutes to display in the UI. This directive applies to all supported browsers except Safari. The browser continues to serve the file from the cache after it has expired, while simultaneously requesting a new copy.

To see component updates without a delay during debugging or testing, enable debug mode.

The Enable secure and persistent browser caching to improve performance option in the Session Settings setup page has no impact on HTTP caching for custom components.

Note

Requests for the Latest Component Version 

After Lightning Experience has been bootstrapped, the component definition is served from the cache if it’s preloaded during bootstrapping. Otherwise, the browser requests the latest version of a component definition. The server responds with a 302 redirect to the specific version of the component.

To view the redirect in Chrome DevTools, go to the Headers tab on the Network panel. A request URL with a redirect contains the uid=LATEST parameter and has a status code of 302. For example:

1https://lng-dev-ed.lightning.force.com/auraCmpDef?_au=zrAD0qv6qvYSMksnSeQhvg&_c=false
2&_density=VIEW_ONE&_ff=DESKTOP&_l=true&_l10n=en_US&_lrmc=-386269907&_style=1474136371
3&aura.app=markup://one:one&aura.mode=PROD&adminsuccess=init
4&one=lexOnboardingManagerService,maskContainer,onePreloads,sidebarWrapper
5&runtime_iag_core=onboardingManager&_uid=LATEST

The redirect points to the following URL that contains a uid=117337808 parameter and has a status code of 200. For example:

1https://lng-dev-ed.lightning.force.com/auraCmpDef?_au=zrAD0qv6qvYSMksnSeQhvg&_c=false
2&_density=VIEW_ONE&_ff=DESKTOP&_l=true&_l10n=en_US&_lrmc=-386269907&_style=1474136371
3&_uid=117337808&adminsuccess=init
4&aura.app=markup://one:one&aura.mode=PROD&one=sidebarWrapper,lexOnboardingManagerService,onePreloads,maskContainer
5&runtime_iag_core=onboardingManager

Since the component version can change at any time, the redirect ensures that the your browser receives the latest version of the component.

Caching Directives for Custom Components 

Custom components return the Cache-Control HTTP header with the following response directives.

1private,max-age=300,stale-while-revalidate=300
  • private- Indicates that the response can be stored only in a private cache, such as a local cache in a browser.
  • max-age=300 - Indicates that the response remains fresh until 300 seconds after the response is generated. Indicates that caches can store this response and reuse it for subsequent requests while it’s fresh.
  • stale-while-revalidate=300 - Indicates that the cache can reuse a stale response while it revalidates it to a cache.

stale-while-revalidate allows the browser or the CDN to continue to serve the file from cache after it has expired (for the next 5 minutes) while it requests a new copy of the component. Therefore, the browser can be up to 10 minutes out of sync with the server for the given component. This directive applies to all supported Lightning Experience browsers except Safari.

The caching header doesn’t apply to components in debug mode.

See Also

Release Preview

This release is in preview. Features described here don't become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can't guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.