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: https://github.com/distantnative/embed

Thereā€™s also this plugin, have never tested it: https://github.com/jenstornell/kirby-time-cache, 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.

Succes!
Bart

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.