Introduction to WordPRess caching
A beginner’s introduction to WordPress caching
The best introduction to WordPress caching I've ever heard goes something like this:
Me: "What’s 1,234,567 divided by 9,721?"
You: "Er, no idea ..."
At this point you take out a phone or calculator and work out the answer.
You: "It's 127!"
Me: "Once more, what's 1,234,567 divided by 9,721?"
You, immediately: "127!"
That’s exactly how caching works.
It's pretty obvious how it works for the example above; you've already done the calculations and worked out the answer.
It's now in your head.
When I ask you the same question again, you need to spend no time working it out or calculating anything.
You can serve the answer up to me right away.
But, how do we put the above example into the context of browsing the internet?
The problem with WordPress page loading speed
Here’s a very basic example of how a website gets from its web server to appear in your browser:
My browser wants to load the page above, so it asks the web server, can I have this page, with this image? The server answers, yes, and the image is downloaded over the internet to my computer, where my browser loads it into view.
Actually, this request happens dozens of times for each web page; multiple requests are sent to get all the text, images, scripts and other files needed to display the page properly. (Reducing the number of these requests is obviously another area you can speed up your website.)
To show how often this back and forth happens, here's part of the load sequence for this very webpage. You don't need to understand it. Just note that each row represents something being requested from the server.
Now, when the next person comes to my website and lands on this page, they need to go through that whole process again. Their browser needs to send each and every request to the server, one by one. And the server answers each request, one by one.
The same for the next person.
And the next.
WordPress caching to the rescue
This is where WordPress caching comes in.
When the first person comes to the page, the final rendered page sent to the browser is saved, or "cached" on the server (from French "cacher", meaning "to hide").
Now, when a second person arrives at that same web page, the page doesn’t have to be rebuilt from scratch. The server checks it’s history and realises “oh, I’ve already built this page for someone”.
It can just send out that saved version to the next visitor.
And to the next. And the next.
It’s just served up from the cache and sent out.
Obviously this means it’s faster. Much faster. Except for poor visitor number one who does all the work.
Now, in reality, caching is much more complex. Usually there are multiple levels of caching happening at once. Typically your browser does some caching on your own computer.
WordPress itself can also do some caching without a plugin.
If you use a CDN that might also use it's own caching.
My Sucuri firewall does caching, too.
And let's not forget the multitude of caching plugins for WordPress, each with their own unique way of doing things.
Problems with WordPress caching
The more astute of you might have noticed a potential problem with this approach. What if the website page changes at any point? Won’t that mean the cached version is out of date?
Yes, it will mean exactly that.
The single biggest problem with caching is that you might get an out of date version of the website page you visit.
If you’ve ever edited a web page and checked it in the browser only to see the old version, this is most likely what’s happening.
The more complex the caching used on your website, the tougher the caching problems you can come across.
Help with caching problems
Some browsers are more stubborn at caching than others, refusing to serve up the latest version of that page.
To that end, here are some things you can try to get the latest version of your website page
- Try holding down the Shift key while pressing the Refresh button
- Clear the cache via plugin settings. There are thousands of articles online on how to do this.
- Close your browser and re-open it
- Use an alternative URL for the same location. For example, if you are going to www.yourdomain.name, you might go to your IP address instead. (You can find your IP address from your hosting).
- Use a different browser (if you use IE, try Firefox, and vice versa).
- Make sure your plugin is set to clear the cache any time a page is updated
- Disable caching for pages with passwords or licencing information.
- Wait. And wait some more. Until the cache clears itself.
There are a host of workarounds to make out of date websites less likely.
But at the end of the day it's a common occurrence and it's part of the price we pay for higher WordPress website speeds.
Hopefully this served as a little introduction to WordPress caching. You now understand a bit more about caching than most folk. In an upcoming article I'll expand on this by going into the types of caching and how to use them effectively to increase your WordPress website speed.
In the meantime, for all the websites I visit that have already been cached… my gratitude goes to visitor number 1 for your speed sacrifice.
Thanks for reading and if you found this useful please hit one of the share buttons. It would mean a lot to me and it helps others find the article.
Thanks to Peter Chester of Modern Tribe for the caching explanation.