TL;DR: When users visit your website, some of the website files are stored so the experience is faster and better for future visitors. This is called “caching.”
- What is caching?
- Why is caching important?
- WordPress caching layers
- How to set up caching for WordPress?
“Caching”—it’s a word you’ve likely heard many times when creating your website and establishing your business. You’ve probably even cleared it occasionally when prompted to. But have you ever stopped to find out what it actually means and how it helps your website?
Well, caching is an important factor in website speed and also allows you to handle more traffic on your WordPress site. But before we get into that, let’s take a look at what caching is.
What is caching?
Whether you’re on a computer, laptop, or smartphone, when you try to access information from a website, a request will be made to the server hosting the website. Often, it can take some time to retrieve this data, return it, and render it for display.
Instead of having to make a full request for all the data every time, caching can be used to store temporary data that makes it easier for the browser, server or database to retrieve it.
Imagine working at a desk within an office (a browser). Across the street is a library (the server). Anytime you need some information from the library, you need to get up from your desk, walk out of the office, across the street, enter the library, ask the librarian (database) to help you find several books (data) with the information you’re looking for, compile information from each of the books into a report (website page), return to the office, walk back to your desk, and finally use the information as intended (display of the webpage).
Caching works by storing a copy of the books required to build the report. The next time someone needs the same report, the copies are ready to be consumed without talking to the librarian or waiting for the data to be put together.
Why is caching important?
With a basic understanding of what caching is, you might be wondering what the benefits are to you and your website.
Provided you have the proper mechanisms in place, caching will:
- Reduce the amount of required system resources. The server hosting your website will need much less power as less requests need to be processed.
- Handle more concurrent traffic. If the server isn’t working as hard, more visitors can visit your website at the same time and view the cached pages.
- Save money. Since your server requires less resources for your website to load and can handle more traffic, you won’t have to increase your server size as traffic increases.
- Improve performance. As you can imagine, if the server isn’t working as hard, WordPress will load faster and provide a much better user experience.
WordPress caching layers
WordPress has several moving parts to generate the requested page or post being requested. There is the user’s browser making the request, the server containing the code files (i.e. PHP, CSS, JS), and the database holding all of the website’s dynamic content.
By default, every time any page is requested by a user, WordPress needs to query the database for the necessary content, compile the data with the necessary files to render the page, and finally send it back to the user. As you can imagine, if the page content hasn’t changed, this process is extremely inefficient.
Caching to the rescue!
At each stage of the request journey, caching can be implemented. The three layers to caching in WordPress are:
- Browser caching
- Page caching
- Object caching
Returning to our analogy from earlier, browser cache is per user. In other words, if another person was in the same office, even though you’ve already made a trip to the library to make a copy of the books you needed, they would need to make the trip to make their own copy of the information themselves.
Because of this, browser caching doesn’t really help with server response time or throughput (the time it takes to go to and from the library/server). What it does do is reduce the amount of data that is required to be sent from the server to the user’s browser on subsequent website visits by a user. By the browser storing static files such as images, these assets will not need to be transferred from the server on the next view because the user already has them stored locally (in the office) and the web page will appear to load much quicker for that individual user.
Browser caching is configured by adding specific details to the data as it is sent from the server back to the browser.
Keep in mind, with browser caching, once a static asset is cached by a user’s browser (or 100k browsers), you, the website owner, won’t have the ability to tell the end user’s browser to uncache it without changing the asset’s url.
Page cache is as if the compiled report is ready to pick up and bring back to the office from the library as soon as you get there because someone else has already generated it for you. A trip to the library is still required, but the information needed is ready to go immediately.
With page caching, the server essentially stores each page of a WordPress website as a static HTML page eliminating the need to get information from the database or compile the different files together to render the page on each request. This will significantly improve response time for user and server throughput allowing the server to handle more concurrent requests.
Generally, page caching will need to be disabled for pages that display personalized content (i.e. ecommerce cart and checkout pages, etc.) and in most cases be automatically disabled for logged in users. For both cases, object caching (see below) becomes extremely important.
Keep in mind, implementing several different page caching solutions will likely cause more issues and headaches for you rather than help improve website performance.
Since not all pages can be cached, particularly when running an ecommerce website or a membership website where users are logged in regularly, object cache becomes extremely important in helping reduce the number of requests made to the database.
In our analogy from earlier, the customized report can’t be served to different users, but the same books are still likely used as sources for the individualized report. So, with object caching, we eliminate the work the librarian does to look up and get the books so the next user using the same data for their report won’t have to wait for the librarian and can use the copy of the books to generate their personalized report. The final report will still need to be compiled, but the slow process of relying on the librarian to get the data required has been removed.
By default, WordPress has object caching built in; however, the cache is non-persistent, meaning it’s only available beyond a single request. To take full advantage of object cache, using third party software such as Redis or Memcache will be necessary. If you’re using a good WordPress hosting provider, the installation and configuration of either should be taken care of for you.
How to set up caching for WordPress?
The benefits of caching mean it’s definitely a must-have functionality on any WordPress website. Best of all, you don’t need to have a lot of technical knowledge to set it up as there are a number of plugins available to help you.
Before you dive in, keep in mind, a plugin may not be necessary. A good WordPress hosting provider will take care of caching for you at the server level, which can be much more powerful and effective than a plugin. Some providers will try to upsell you during this conversation. At times these upsells aren’t as efficient as something like WP Rocket (discussed below) and not worth it for you. Other times the provider may ask for an unreasonably expensive fee given how simple the configuration is. If you’re not convinced the deal is fair, it may be time to rethink if your hosting provider is the right one for you.
If you do decide to go with a plugin, the first we recommend is WP Rocket, which is generally regarded as one of the best available on the market. However, the quality does come with a financial catch—the pricing begins at $49 for one website. There is no free trial, although they do have a 14-day grace period where you can change your mind and get your money back.
So, what do you get for this? Quite simply, you get a substantial range of features and unrivaled ease of use. As soon as you activate the plugin, page caching is automatically enabled and you can easily optimize from there.
It also has a good track record of compatibility with other plugins and offers features such as:
- Media lazy loading
- Cache preloading
- CDN integration
- Database optimization
W3 Total Cache
However, it’s not as easy to use as WP Rocket and, unless you’re somewhat tech savvy, you may have to pay for the premium support (which will also come with additional features).
WP Super Cache
Finally, we have WP Super Cache, which is an entirely free, open-source plugin from the company behind WordPress. Unsurprisingly, giving its authority and price point, it is one of the most popular caching plugins for website owners.
What it lacks in features, it makes up for in ease of use, allowing you to enable caching with a single switch. There are more advanced options available, but it doesn’t reach the same level as either W3 Total Cache or WP Rocket.
Bottom line, caching isn’t simply a useful feature that you should consider trying out. It’s a fundamental part of ensuring that repeat visitors keep coming back. If you don’t currently have caching set up, it’s definitely time to implement it as part of your browsing experience.
If you’re struggling to implement caching for your website, we can help with a one-off website consultation.