Cache Primer or How-To?

Are there any docs about how to setup and use Kirby’s built-in caching in different scenarios?

I have a customer who is working with an SEO specialist, who wants to speed up page loading times, so I’m guessing that turning caching on will help…?

I am, however, concerned about understanding how the whole caching mechanism works - what gets cached, where, and when does it get updated - and whether there are any ‘gotchas’ that we should be aware of.

Any hints would be greatly appreciated.

The default cache only caches complete pages, i.e. the complete html of a rendered page together with some meta data.

The complete cache gets deleted if any page is updated.

You can’t use the cache on pages with forms or pages where access to certain parts should be restricted.

Thank you for the quick reply, @texnixe!

So, if in my site I have a contact form or newsletter subscription form in the FOOTER - which appears on every page of the site - then there is no point in turning the cache on?..

Excactly, with forms on every page, the native cache doesn’t make sense.

You can, however, use the cache methods to write parts of your page or results of functions to the cache. Some plugins do that, you can check out some examples of how to do that.

An example is the Embed plugin:

There’s also this plugin, have never tested it:, but might be a starting point.

Caching is a good thing. Always try to cache.

Imho it’s a lazy excuse to not cache pages because of a form in the footer. Without knowing your entire use case, you could even use the file cache in your setup as follows:

  • You could post the form to another page (which is excluded from the caching).
  • You could enhance that experience by using AJAX.


Yes, that would work, but only if you get a fresh csrf token via Ajax, because a cached page retains its old CSRF token.

If your templates don’t contain any complex logic (like displaying a huge list of pages that are filtered and sorted) and if they don’t depend on data from an external API, the render time of a Kirby page itself is already quite fast.

The “page load time” mostly consists of assets like JS files, images and ads. Caching pages in Kirby definitely makes sense, but if you need to jump through a lot of hoops to implement it, I would first look into the other parts of the page where the optimization effect is often larger.

Thank you for the guidance, and the suggestions, guys - truly appreciated.

After some initial page loading time analysis, it seems that about 70% of the initial loading time is due to pre-loading of the many images within the pages. We will now investigate alternative ways of improving that by using ‘lazy-loading’ JavaScript libraries, and perhaps moving some of these static assets to CDN. This will probably have a bigger impact on loading times than turning on the cache.

Once again, many thanks for your input and guidance.