img-1

Default cache strategy and overrides

Since RabbitLoader uses optimization and integrated caching with CDN, there are some default cache strategies in place for various resource types.

CSS and JavaScript caching behavior

All CSS and JavaScript files are cached on CDN servers indefinitely, a practice commonly referred to as immutable caching. The cached content remains static unless there’s a modification in the file name or version specified in the URL, or a complete purge is executed. For instance, let’s consider a scenario where a theme.css file is included in an HTML page as follows:

<link rel="stylesheet" href="https://example.com/styles/theme.css?v=1.0" />

Upon the initial request for the theme.css file via the CDN server, it gets stored with the hash of its URL, including the version v=1.0, and remains cached indefinitely. If any changes are made to the file content without updating its version in the URL, the latest modifications may not reflect until a full purge is performed. The recommended approach to implementing new changes is by incrementing the version number in the file:

<link rel="stylesheet" href="https://example.com/styles/theme.css?v=2.0" />

This method ensures a seamless rollout of updates without the need for explicit purging.

Image caching behavior

Similar to CSS and JavaScript files, images are cached on CDN servers for an indefinite period, a practice known as immutable caching. The cached content remains unchanged unless there is a modification in the URL, such as altering the file name or the version identifier within the URL. Hence, it is advisable to update the image file name or incorporate a version query parameter in the URL whenever the image undergoes resizing or any other alteration.

<img src="https://example.com/images/logo.jpg?v=1" />

<img src="https://example.com/images/logo.jpg?v=2" />

Setting the default cache duration

All assets are by default cached for a lifetime and change only if the URL parameters change. The default cache duration can be set to any value via Page Rules. Please have a look at the page rules introduction if you are new to this.

Navigate to edit an existing page rule, or create a new one. In the last step of the page rule, you can set how long the content can be cached. Though the recommended value is immutable/forever, you can choose any value if you are aware of its performance.

page-rule-cache-duration

Based on headers from the origin

When this option is selected, the cache duration is decided by the origin server. You get the flexibility to control the cache duration via web server directives or .htaccess rules.