---------------------------------------------
Some of our members are trying to make their Joomla sites run more quickly. They've seen caching options, which promise to help speed up their sites. But, there are several caching options available.
This blog post explains what options are available and how you can enable them.
This tutorial borrows from
this article by Klas Berlič. All of the detailed technical explanations and image are from Klas, so a big thank you to him.
What is a cache? A cache stores all or part of a web page so that it doesn't have to be pulled from the database. By not needing to connect to the database, a website can respond much more quickly to a visitor.
Does caching help? Yes, absolutely! There are many ways to speed up a Joomla site, but we often see far better results from caching than anything else. As Klas explains in his post, retrieving stored website pages is up to 10 quicker than waiting for them to be created.
Here's a graph shared by one of our members, via
Pingdom.com, showing the speed change of their site after enabling the cache.
Option #1: Cache Settings Go to System > Global Configuration > System. You'll see an area called Cache Settings with these three options:
- OFF - Caching disabled
- ON - Conservative caching
- ON - Progressive caching
Here's the default tooltip explaining the difference between the two ON options.
- Conservative caching: smaller system cache.
- Progressive caching: faster, bigger system cache, includes module renders cache. Not appropriate for extremely large sites.
Let's get a little more specific about the difference between those two:
- Conservative caching: This allows a site administrator to choose which modules are cached. You can login to each module and enable for them individually. Conservative caching is better for frequently updated sites - you can remove caching from your modules that contain dynamic content.
- Progressive caching: This takes a snapshot of each unique set of modules on a page, so many modules can be cached at once. This affects all modules and overrides any cache settings inside individual modules. Progressive caching is better for sites that don't update very often.
This image from Klas shows some of the areas that might be covered by the progressive cache:
Here's an example of a module with cache settings. Notice that there is no "Enable caching" setting. There are only these two choices:
- Use Global: cache this module if Progressive or Conservative caching are enabled.
- No caching: don't cache this module if Conservative caching is enabled.
Option #2: Cache Handler Inside System > Global Configuration > System, there is a second option called "Cache Handler". This allows to move away from the default setting but this is harder to use. To use anything except the "File" option, you must have appropriate PHP extension installed.
Option #3. Platform Specific Caching In addition to the other caching options, you'll also get the ability to specific different caches for different device. This allows you to cache one version for desktop users, another for tablet users, and yet another for mobile users:
Here's the description for this setting:
Option #4: Cache Time Inside System > Global Configuration > System, the third options is Cache Time. The more dynamic your site is, the lower this time should be.
For example, if you leave this setting to 15 minutes, your page will only appear to change every 15 minutes. If your site is updated more frequently, change this to a smaller time. If your site is rarely updated, you can set this to a larger number.
Option #5: Page Cache To turn on the page cache, go to Extensions > Extension Manager and enable the System - Cache plugin.
In Klas' words, here's what the page cache does:
"Takes snapshots of entire pages including everything - component, modules, plugins and a template. It is the fastest, the widest and the least flexible approach of all caching options."
This image below from Klas shows which areas will be covered by the page cache. In short, the page cache covers the whole page.
Option #6: Browser Cache To turn on the browser cache, go to Extensions > Extension Manager and edit the System - Cache plugin. Set Use Browser Caching to Yes.
With browser caching, every time someone looks at a page or an image the browser keeps a copy of it. Then if you request that page again within a certain amount of time, rather than run out to the internet to grab a new copy, it just gives you the locally saved version. This make your site feel much faster.
--------------------------------------------------------------
Conservative caching is the standard type of caching. Heres how it works:
A visitor visits a page on your website.
Joomla checks if there is a non-expired version of that page in its cache directory.
If the cached page exists (and its not expired), then Joomla will serve it to the visitor otherwise, a cached version of the page is created, and that cached version will be served to the visitor, and to every other consequent visitor, as long as its (by it we mean the page) not expired. The above scenario is typical and is how most developers implement caching.
Progressive caching works the following way:
A visitor visits a page on your website.
Joomla checks if a cached version of that page exists for that visitor and its not yet expired.
If that cached page exists, then itll be served to the visitor, otherwise, Joomla will create the cached page for that specific visitor and then will serve it to him.
If another visitor (who has never been on that page) visits that page, then Joomla will not serve the cached page of the previous visitor, instead, it will create a cached version of that page
specifically for that user, and then serves it to him.
As you can see, progressive caching only offers a performance improvement if the same visitor visits the same page within the lifetime of the cached version of the page. In most scenarios, progressive caching results in a huge performance hit that is far worse than disabling cache, simply because for nearly every visit, Joomla has to process the request, create the cached version of the page, and then serve the page to the visitor (instead of just processing the request and serving the page in the scenario where cache is disabled). Oh, and dont forget about all the cache files generated by Joomla you can only imagine how many of these files you will have in your cache folder if you have a high traffic news website (that has many pages).
Now you might wonder, under which circumstances is progressive caching useful? Well, imagine that you have a video website (similar to youtube). You want to show each visitor customized pages based on his location and/or browser settings and/or plugins installed. So, for every page that the visitors loads, you use this information to generate a customized version of that page and you cache it. If the visitor visits that same page again, then Joomla doesnt need to redo the work to generate the customized page.
Of course, there are many scenarios under which progressive caching is really useful, but in our opinion, progressive caching should only be considered if the website receives many visitors and if those visitors are mostly repeat visitors. Using it in other cases will cause a significant hit on the websites performance.