Cloudflare cache for ecommerce: what you need to survive the peak
During Black Friday the weak point of WooCommerce or custom stores is almost always the origin server: PHP and the database receive more requests than they can serve, pages slow down and checkout times out. Cloudflare can absorb part of that traffic, provided you know what to cache and what not to. Getting it wrong has a concrete cost: a visitor sees someone else's cart, or an old price stays online for hours.
The short answer: keep static files cached (Cloudflare already does), consider adding catalogue HTML for anonymous visitors with a short lifetime, always exclude cart, checkout, account and requests with session cookies, purge the cache when prices change and test everything before the weekend. This article is about the CDN; application caching on the backend is a different layer, covered in our article on invalidation and cache stampedes.
What can be cached in an online store
According to Cloudflare's documentation, the CDN does not cache HTML or JSON by default. It caches files by extension: CSS, JS, images (JPG, PNG, WEBP, AVIF, SVG), fonts, PDF and other static formats. A response is not cached if the origin sends Cache-Control: private, no-store, no-cache or max-age=0, if it includes a Set-Cookie header, or if the method is not GET.
Pages fall into three groups:
- always cached: images, CSS, JavaScript, fonts;
- cached with a short TTL, anonymous visitors only: homepage, categories, product pages, information pages, blog;
- never cached: cart, checkout, account, admin area, AJAX and API calls.
If prices change by visitor country or currency through a geolocation plugin, do not cache HTML: the same URL would produce different prices and the cache would serve everyone the first visitor's version.
Pages and cookies to always exclude
WooCommerce's documentation says to exclude the Cart, My Account and Checkout pages from caching, because they show data for a single customer. Use your store's real slugs: on non-English stores they are often translated, so check them under WooCommerce settings rather than assuming /cart/.
Also exclude requests carrying these cookies:
woocommerce_items_in_cartandwoocommerce_cart_hash: the visitor has something in the cart;wp_woocommerce_session_: an active WooCommerce session;wordpress_logged_in_: a logged-in user.
Finally exclude /wp-admin/, /wp-json/, requests with wc-ajax and those with the add-to-cart parameter.
Cache rules: step-by-step setup
Cache rules are created in the Cloudflare dashboard, in the domain's Caching section. The Free plan allows 10, Pro 25, Business 50. One detail decides everything: rules matching the same request stack, and when two settings conflict, the last one wins. The exclusion rule therefore goes at the bottom of the list.
Rule 1: catalogue HTML
Condition: hostname equals your domain. Action: eligible for cache, with an Edge TTL that ignores the origin header and uses a short lifetime, for example 10 minutes. For Browser TTL keep "respect origin" or choose a short value, so customers' browsers don't hold on to old prices.
Rule 2: exclusions (at the bottom)
Action: bypass cache. An example expression, to adapt to your store's slugs:
starts_with(http.request.uri.path, "/cart") or starts_with(http.request.uri.path, "/checkout") or starts_with(http.request.uri.path, "/my-account") or starts_with(http.request.uri.path, "/wp-admin") or starts_with(http.request.uri.path, "/wp-json") or http.request.uri.query contains "wc-ajax" or http.request.uri.query contains "add-to-cart" or http.cookie contains "woocommerce_items_in_cart" or http.cookie contains "wp_woocommerce_session_" or http.cookie contains "wordpress_logged_in_"
Keep "serve stale while revalidating" on: when a copy expires, Cloudflare keeps serving it while refreshing it in the background, so the origin doesn't receive every request at the same moment.
Images, CSS and JavaScript
These files are already cached by extension and usually make up most requests. You can raise the Browser TTL, because WordPress adds a version parameter (?ver=) to theme and plugin files and the URL changes on every update. Before the peak, check the weight of images for products on promotion: a 2 MB file served from cache is still slow to download on mobile.
Purging the cache during promotions
When prices change, cached pages must be refreshed. Cloudflare allows purge by URL, hostname, tag, prefix and full purge on every plan. The limits differ: on the Free plan, hostname, tag, prefix and full purges are limited to 5 requests per minute. A 200 response only confirms the request was received, so check that CF-Cache-Status is no longer HIT.
A full purge in the middle of the peak sends every request to the origin at once. It is better to update prices and purge just before the promotion starts, then purge only changed URLs or prefixes during the weekend. Before any major change to the store, make sure you have a recent WooCommerce backup.
Checking the cache hit ratio before the weekend
Open a product page in a private window and read CF-Cache-Status in developer tools, or from a terminal with curl -I. The main values:
- HIT: served from cache;
- MISS or EXPIRED: came from the origin, the next request should be a HIT;
- BYPASS: the origin returned a response that could not be stored;
- DYNAMIC: the request was not eligible for cache.
Repeat the test with a product in the cart: cart and checkout must return BYPASS or DYNAMIC, never HIT. Then check the share of requests served from cache in Cloudflare Analytics, as explained in our article on visitors, requests and cache hit ratio.
Pre-peak checklist
- Real cart, checkout and account slugs added to the exclusion rule.
- Exclusion rule at the bottom of the cache rules list.
- No HTML caching if prices change by country or currency on the same URL.
- CF-Cache-Status tested as an anonymous visitor, with a product in the cart and as a logged-in user.
- Purge procedure agreed: who does it, when, by URL or by prefix.
- DNS records for mail subdomains not proxied, as covered in our guide to moving DNS to Cloudflare.
If you want someone to review your store's Cloudflare setup before the weekend, get in touch with your domain and the platform you use.
- cloudflare
- cache rules
- woocommerce
- black friday
- cdn
- picchi di traffico
- purge cache
- prestazioni sito
Frequently asked questions
Does Cloudflare cache store pages without configuration?
No. According to Cloudflare's documentation, HTML and JSON are not cached by default. Files with static extensions such as CSS, JS, JPG, PNG, WEBP and fonts are. To cache HTML you need a cache rule that makes those pages eligible.
Which WooCommerce cookies should bypass the cache?
WooCommerce's documentation lists woocommerce_cart_hash, woocommerce_items_in_cart, wp_woocommerce_session_ and woocommerce_recently_viewed. Add the WordPress login cookie, which starts with wordpress_logged_in_.
How can I tell whether a page came from Cloudflare's cache?
Look at the CF-Cache-Status header. HIT means served from cache, MISS and EXPIRED mean it came from the origin, BYPASS and DYNAMIC mean it was not cached. You can read it in browser developer tools or with curl -I.
Is purging the whole cache during Black Friday a problem?
It can be: right after it, every request goes to the origin server. Purge the changed pages by URL or prefix instead, and if you need a full purge, do it when traffic is low, for example just before the promotion starts.
Sources
- Default cache behavior — Cloudflare Docs
- Cache Rules settings — Cloudflare Docs
- Order and priority of Cache Rules — Cloudflare Docs
- Purge cache — Cloudflare Docs
- Cloudflare cache responses — Cloudflare Docs
- Configuring caching plugins — WooCommerce Developer Docs
- Cache-Control header — MDN Web Docs
Related articles
Server & Domains · 7 min read
Cloudflare Analytics: understand visitors, requests and cache hit ratio
A practical guide to reading Cloudflare unique visitors, requests, data transfer and cache hit ratio without confusing traffic, people and performance.
Digital Systems · 7 min read
Reliable ecommerce caching: invalidation, stale data and cache-stampede protection
An operating model for faster catalogue delivery without serving data beyond its tolerance or overwhelming the origin when popular keys expire together.
Server & Domains · 6 min read
Move DNS to Cloudflare without losing email or your website: a safe procedure
How to move DNS to Cloudflare without breaking mail or the website: record inventory, checking the import, orange or grey cloud, the nameserver switch and a rollback plan.
