All posts

Blog

Types of Website Caching Explained: Browser, Page, Object and CDN Caching

Illustrated cover for the Speed & Performance guide "Types of Website Caching Explained: Browser, Page, Object and CDN Caching"

Ask anyone how to make a slow website faster and the first word you will hear is "caching." It is good advice, but it hides a lot of detail. A modern website can have five or six separate caches stacked on top of each other, each one storing a different thing in a different place. When people say "clear your cache," they often don't know which one they mean.

This guide walks through the main types of website caching, what each one stores, where it lives, and how they fit together. Once you see the layers, speed problems (and stale-content problems) get much easier to reason about.

What caching actually means

A cache is a stored copy of something that was expensive to produce, kept so it can be handed out again quickly. The "expensive" part might be:

  • Running PHP code and database queries to build a page
  • Compiling a script into machine-friendly instructions
  • Sending a large image across the internet
  • Looking up the same database row for the hundredth time

Every cache makes the same trade: you get speed, and in exchange you risk serving something slightly out of date. Good caching setups are mostly about deciding how long a copy can live and when it must be thrown away. That process is called invalidation, and it is the tricky part.

Layer 1: Browser caching

The cache closest to your visitor lives inside their own browser. When someone loads your site, the browser downloads your logo, CSS, JavaScript and fonts. If your server sends the right headers, the browser keeps those files and reuses them on the next page view instead of downloading them again.

The headers that control this are mainly:

  • Cache-Control, for example Cache-Control: public, max-age=31536000 tells the browser it may keep the file for a year.
  • ETag and Last-Modified, which let the browser ask "has this changed?" and get a tiny "304 Not Modified" reply instead of the whole file.

Best for: static files that rarely change, such as images, stylesheets, scripts and fonts.

Watch out for: if you set a long lifetime and then edit style.css, returning visitors may keep the old version. The common fix is "cache busting," which means changing the file name or adding a version string (style.css?v=2) whenever the file changes. Most WordPress themes and build tools do this for you.

Layer 2: CDN and edge caching

A content delivery network keeps copies of your files on servers spread around the world. A visitor in Seattle gets your images from a nearby location instead of from your origin server in another region. Many CDNs can also cache full HTML pages at the edge if you configure them to.

We cover the basics in our guide to what a CDN is, but the caching point is simple: an edge cache cuts the distance data has to travel and takes load off your server.

Best for: static assets for visitors spread across a country or the world, and full pages on sites where content is the same for everyone.

Watch out for: logged-in users, shopping carts and personalized pages. Those must not be cached at the edge, or one visitor could see another visitor's cart.

Layer 3: Page caching (full-page cache)

Page caching happens on your web server. The first time a page is requested, the CMS runs all its code and queries to build the HTML. The page cache saves that finished HTML. The next visitor gets the saved copy directly, with no PHP and no database work.

For a WordPress site this is usually the biggest single speed gain. A page that took several hundred milliseconds to generate can be served in a small fraction of that time. On LiteSpeed servers, the LiteSpeed Cache plugin handles this at the server level; we walk through it in speeding up WordPress with LiteSpeed Cache. Other setups use plugins that write HTML files to disk, or a reverse proxy such as Varnish or an Nginx cache.

Best for: blogs, brochure sites, news pages and any page that looks the same to most visitors.

Watch out for: pages that must be fresh or personal, such as checkout, account and cart pages. Good cache plugins exclude these automatically, but always check after installing one.

Layer 4: Object caching

Not every page can be fully cached. Logged-in dashboards, WooCommerce carts and membership areas have to be built on the fly. Object caching speeds those up by storing the results of individual database queries and computed values in memory.

Instead of asking MySQL for the same site options or menu items on every request, the application checks the object cache first. Redis and Memcached are the two common tools for this. We go deeper in our guide to Redis object cache for WordPress.

Best for: dynamic sites, stores, membership sites, and admin areas that feel sluggish.

Watch out for: object caching does little for a small static blog that already has page caching. It shines when lots of uncached, database-heavy requests happen.

Layer 5: Opcode caching (OPcache)

PHP is a scripting language. Each time a PHP file runs, it has to be read and compiled into "opcodes" before execution. OPcache stores those compiled opcodes in memory, so PHP skips the compile step on later requests.

OPcache is built into PHP and is enabled on most hosting servers. You rarely need to touch it, but it is worth knowing it exists. See our explainer on PHP OPcache for details.

Best for: every PHP site. It is close to free speed.

Layer 6: Database query cache

Databases have their own internal caches, mostly keeping frequently read data and indexes in memory (in MySQL and MariaDB, the InnoDB buffer pool does much of this work). Note that the old MySQL "query cache" feature was removed in MySQL 8.0, so if you read older tutorials telling you to tune it, they may not apply to your server.

On shared hosting you won't usually control database settings. On a VPS you can, and buffer pool size is one of the first things worth reviewing.

How the layers work together

Picture a single visit to a WordPress blog post:

  1. The browser checks its own cache for the CSS, JavaScript and images.
  2. Anything missing goes to the CDN, which may have a copy at the edge.
  3. If the CDN doesn't have the page, the request reaches your server, where the page cache may answer immediately.
  4. If the page isn't cached, PHP runs (fast, thanks to OPcache), and the application asks the object cache for data before falling back to the database.
  5. The database answers from memory where it can.

Each layer catches requests the layer above missed. You don't need all of them, but the more traffic you get, the more each one is worth.

Which caching do you actually need?

A practical starting point:

  • Small blog or business site: browser caching plus page caching. Add a CDN if your visitors are spread out.
  • WooCommerce or membership site: all of the above, plus object caching for the dynamic pages.
  • Custom PHP application: OPcache (usually already on), object caching for repeated queries, and careful HTTP cache headers.

When to clear which cache

When a change doesn't show up, work from the outside in:

  1. Hard-refresh your browser or test in a private window.
  2. Purge the CDN cache if you use one.
  3. Purge the page cache in your cache plugin.
  4. Flush the object cache if you changed settings or data directly in the database.

Clearing everything at once works too, but it means your server has to rebuild every page from scratch, which can briefly slow down a busy site.

Wrapping up

Caching isn't one setting; it is a stack of layers, each saving a different kind of work. Browser and CDN caches save network trips, page caches save whole page builds, object caches save repeated database queries, and OPcache saves PHP compile time. Set up the layers that match your site, learn how to purge each one, and you will have solved most website speed problems before they start.