What happens when a page loads

When a visitor opens a WordPress page, the server has to run PHP code, fetch text, products and settings from the database and assemble the final page from all of that. For one visitor it does not matter, but with hundreds the server keeps repeating the same work for nothing. A cache stores the finished page and sends it straight to the next visitors.

Caching happens at several levels:

  • Page cache on the server stores complete, finished HTML pages.
  • Object cache (for example Redis) remembers the results of frequent database queries.
  • Browser cache stores images, styles and scripts on the visitor’s computer or phone, so they are not downloaded again on the next page.
  • A CDN keeps copies of files on servers closer to visitors.

Why it matters

A fast website scores better on Core Web Vitals and fewer people leave it. Caching also takes load off the server, so the site copes better with traffic spikes, for example during a sale or after a newsletter goes out. It is often the cheapest speed-up you can make.

A real example

A guesthouse in the Tatras has a website with a gallery and price list. Without caching, the home page is built from scratch on every visit, which takes noticeably long on cheap hosting. With page caching switched on and browser caching set up, visitors are sent the finished page, and when they move to another page the header photos and fonts are not downloaded again.

Where caching causes problems

  • Basket and account pages in an online shop. These pages are different for every customer and must not be cached. Otherwise one customer could see another’s basket. A good setup excludes them from the cache.
  • “I changed the text but I cannot see it.” After an edit the cache needs clearing, or it should be set to refresh itself when content changes.
  • Several caching plugins at once. Two plugins doing the same thing often get in each other’s way, and the site may stop working properly.
  • Caching as a sticking plaster. If the site is slow because of a heavy theme and dozens of plugins, caching only helps partly. Logged-in users and the admin area stay slow.

How I handle it at 5pixel

When speeding up websites, I first find out what is really slowing the site down and only then set up caching – excluding the basket, checkout and customer account, and clearing the cache automatically when content changes. I also check that caching still works properly after updates as part of website maintenance.