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.
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:
The redirect points to the following URL that contains a uid=117337808
parameter and has a status code of 200. For example:
Since the component version can change at any time, the redirect ensures that the your browser receives the latest version of the component.
Custom components return the Cache-Control
HTTP header with the following response directives.
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