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 files and JavaScript files are cached at CDN servers for a lifetime. This is also known as immutable caching, the cached content never changes unless the file version in the URL changes or a full purge is executed. For example, let’s say there is a theme.css file. This is how typically the file is included in an HTML page-

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

Now, when the theme.css file is requested the first time through the CDN server, it is saved with the hash of its URL, which includes v=1.0 as well, and it’s cached forever. If the file content is modified without changing its version in the URL, the latest changes may not reflect unless you execute a full purge. The best way to roll out new changes is to increment the version number in the file. This is seamless and does not require any explicit purge.

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

Image caching behavior

Similar to CSS/JavaScript files, images are cached at CDN servers for a lifetime, also known as immutable caching. The cached content never changes unless the file version in the URL changes. Therefore, it is recommended to change the image URL, or use a version query parameter in the URL whenever the image is resized or any other modification is done.

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 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.

Immutable/Forever

When this option is selected, the content is cached forever but changes automatically when the version parameter in the URL changes. This is recommended option for RabbitLoader users.