Caching with Kirby

Hi, I have found documentation that will enable caching with Kirby: Caching | Kirby CMS. I have gone with the first option of enabling Kirby’s page cache in my config.php by adding the code provided. I have run a speed test on my website with google speed test and I am still getting advisories to cache my website. Is this automatic or do I need to wait sometime for the cache to be active? Furthermore, can I flush my cache?

Google complaining about caching refers to HTTP caching, see HTTP Caching  |  Web Fundamentals  |  Google Developers

Kirby’s cache is auto-flushed when content is changed via the Panel. The Janitor plugin also provides a way to manually flush the cache.Janitor | Kirby CMS

so is the cache working fine, its google buggin out?

It’s two different things, see the link posted above.

Kirby caches the PHP generated HTML, so that it doesn#t have to be re-generated again as long as the cache is valid.

thanks for the advice is it possible to cache images, videos and other media?

That’s exactly the point. Files are cached by browsers and with expiry settings or cache headers you determine how long this stuff should be cached by the browser by default.

Hi, @JaquilineBrown! The whole topic of ‘caching’ can be confusing, because there are many different caches involved. The whole point of caching web pages and resources is to try and speed up the page loading times, so there’s several places where the ‘caching’ can happen:

  1. Browser cache: when you visit a web page, your browser can cache the images, stylesheets and script files for the page - which makes accessing the same page in the future faster.

  2. Web server cache: the web server can sometimes have a ‘cache’ of previously-requested pages, where it keeps pages that are visited often. This means that it can retrieve pages from the cache, rather than have to ask PHP/Node/Python/whatever dynamic server language you’re using to generate the page (again).

  3. PHP Cache: the PHP processor can use a ‘cache’ to store pages that have been requested recently. That means that if the web server asks for a page that it has just generated, it can simply give the server the page from the cache, saving a little processing time.

  4. App Cache: this is like the cache you can set in your Kirby config. Sometimes, the web app you’re using will have its own way to ‘cache’ the pages you generate with it, so that instead of getting PHP to generate the page dynamically, it can simply return the previously generated, cached version.

The Google tool you used is only concerned with browser caching - that is, #1 above. Usually, it is the job of the web server where your site is hosted to tell the browser whether to cache those resources (images, script files, etc.), and for how long. The web server uses ‘headers’ in its communication with the browser, to tell it to ‘cache’ or ‘not-cache’, and how long to keep each file.

In our web servers, for example, we use 2 different configurations our sites: one for ‘staging’ sites, and one for ‘production’ (live) sites. In the ‘staging’ configuration, the server always tells the browser to cache nothing: this means that every time we visit the site, the browser should get the images, scripts and stylesheets anew. This is what you want while you’re developing, so as you update your images/styles/scripts, you see the changes take effect on the browser, and not a previously cached version. On ‘production’ sites, however, we tell the browser to cache all those static assets for 6 months - that’s pretty standard. That’s because the media (images, videos), scripts and stylesheets don’t change that often, and are usually responsible for about 90% of a page’s total loading time. So if your browser can just load a local, cached copy next time it visits the page, it means a massive speed increase on your live site.

If your server is not setup to send out the appropriate cache/no-cache headers, the easiest solution is to contact your hosting provider, and see if there is a way for you to customise your server configuration. If there is, then you’re in luck - and we might be able to help you a little more.

4 Likes

@kirbyzone Thank you so much for your message i really understand caching now, and furthermore, I can also understand why I was confused in the first place. I will contact my hosting provider now and ask for some further assistance.