← News / all articles
Optimization

WooCommerce optimization layer by layer: cache, Redis, database and Core Web Vitals

· 5 min read

A slow WooCommerce store rarely has a single cause. A product page may be waiting on PHP, on the database, or on images and scripts in the browser, and a single speed-up plugin usually covers only some of these layers. That is why optimization is best done layer by layer: from server configuration and cache, through the database, to the way assets are loaded.

Context

WooCommerce combines content that caches well with data that has to be generated for a specific customer. The second group mainly includes:

  • the cart and the checkout process;
  • the customer dashboard and account pages;
  • interface fragments showing the cart contents;
  • individual prices, discounts and data that depend on the logged-in user.

On top of that come the assets of many plugins, loaded even on pages that don't use them, and a database that grows with the store: temporary data, operation history, product metadata and leftovers from removed plugins.

Each of these areas can be a bottleneck. The home page, a category, a product page, the cart and checkout can also have entirely different limits, so they are worth measuring separately.

Solution

Cache at the right level

Depending on the server architecture, different levels of caching are used:

  • Redis Object Cache: results of operations and queries in memory, less work for the database;
  • Varnish Cache: caching HTTP responses at the reverse proxy level;
  • NGINX FastCGI Cache: caching generated PHP responses directly on the server;
  • Browser Cache: storing static assets in the browser's cache.

The key is separating static and dynamic content. A misconfigured cache in WooCommerce can show outdated data, break the cart, and even expose the session contents of other customers.

WP_CACHE and Redis

The WP_CACHE constant in wp-config.php lets WordPress use the caching mechanisms provided by the appropriate components:

PHP
define( 'WP_CACHE', true );

The constant alone, however, neither starts Redis nor caches pages. You need a persistent object cache, a working connection to the Redis server, and a check that caching actually works: the number of read and write operations, the cache hit ratio, and the effect on SQL queries.

LiteSpeed Cache or WP Rocket

The choice of plugin should follow from the infrastructure, not from its popularity. LiteSpeed Cache integrates with LiteSpeed and OpenLiteSpeed servers, including page caching and Edge Side Includes (ESI). WP Rocket offers frontend optimization and caching mechanisms that work in various hosting environments. The result depends on the server, the cache configuration, the number of products, the plugins and the traffic profile.

Exceptions for dynamic elements

Where the environment allows it, selected dynamic fragments can be generated independently through ESI. In other configurations you need to define cache exceptions, cookie rules and WooCommerce session handling. The goal is the same: cache as much as possible without compromising the correctness of the purchase process.

Images

Product images are among the assets with the biggest impact on load time. Optimization includes:

  • conversion to WebP and AVIF formats;
  • sizes matched to different devices, plus the srcset and sizes attributes;
  • lazy loading for images outside the visible area of the page;
  • priority loading of key images in the initial view.

The LCP (Largest Contentful Paint) image should not be delayed by lazy loading. The width and height attributes and CSS aspect-ratio let the browser reserve space for an image early, which limits the layout shifts measured by CLS. alt attributes improve accessibility and help search engines, but they don't speed up the store; purely decorative elements can have an empty alt.

CSS and JavaScript

The work includes loading scripts and stylesheets conditionally, only where they are needed, removing unused CSS, minification, reducing render-blocking assets, defer or async where dependencies allow it, and tidying up external analytics and marketing tools. In WooCommerce, the order of the scripts handling the cart, product variations and checkout has to be preserved.

Local fonts

Fonts from external sources add network connections and can delay text rendering. What helps is storing the files locally in WOFF2 format, fewer styles and weights, an appropriate font-display value, and preloading the most important fonts if it brings a measurable benefit:

CSS
@font-face {
  font-family: "Shop Sans";
  src: url("/fonts/shop-sans.woff2") format("woff2");
  font-display: swap;
}

Database

The wp_options table needs particular attention, especially the entries loaded automatically. It is worth checking the size and structure of the autoload data, outdated records and orphaned metadata, expired transients, SQL query performance, table indexes, and the load generated by Action Scheduler.

Tools such as WP-Optimize help, but automatic cleanup is no substitute for analyzing the data structure. In larger stores, WP-CLI, custom PHP and SQL scripts, and query analysis help find the sources of problems.

Compression and headers

GZIP or Brotli compression, chosen to suit the infrastructure and asset types, reduces the amount of data transferred. It is also a good moment to check the response headers and the caching policy for static assets.

Measurement and monitoring

Optimization starts with measurement and ends with verification. Useful tools are PageSpeed Insights and Lighthouse, the LCP, INP, CLS and TTFB metrics, and Query Monitor with PHP profiling. Where possible, synthetic test results are worth comparing with real user data.

After deployment, ongoing monitoring matters: PHP and WordPress error logs, HTTP server logs, slow SQL queries, WooCommerce and Action Scheduler errors, problems with external APIs, PHP-FPM load and memory usage, and errors during order placement and payments. Logs must be secured and not publicly accessible.

Limitations

  • There is no single configuration for every store. A small store with little traffic needs a different approach than a platform with thousands of products, B2B price lists, an ERP integration and heavy traffic.
  • Every cache change requires checking the cart, the customer account and checkout, because that is where errors cost the most.
  • Database cleanup should be preceded by a backup and a dependency check, so as not to damage order data or business processes.
  • A good PageSpeed score is not a goal in itself. Synthetic tests don't reveal every problem that shows up in the logs.

A fast WooCommerce store is the result of finding the real bottlenecks and removing them at the right level of the architecture, not of one plugin or one setting.

Choose which optional cookies you agree to. You can change or withdraw your consent at any time in the cookie settings in the website footer. Cookie policy