LiteSpeed Cache for WordPress and a webshop
Our servers run on LiteSpeed. For WordPress, the free plugin LiteSpeed Cache is therefore the logical cache plugin: it stores ready-made pages on the server, so they don't need to be rebuilt on every visit. Your site becomes faster and your package has less work to do. With a webshop, you do need to know which pages should never be cached. This article covers the basics and what's added for WooCommerce.
The basics
- In WordPress, go to Plugins > Add New Plugin, search for "LiteSpeed Cache", check that the publisher is LiteSpeed Technologies, and install and activate the plugin.
- Open LiteSpeed Cache > Cache in the menu and check that Enable Cache is turned on.
- If you're using another cache plugin, disable it. Two caches running side by side can cause strange errors.
- Then test your site in a private window.
Want to know more about why your site is slow and what else helps, read My website is slow or uses too much CPU: here's how to speed it up.
Webshop: two types of pages
| Page type | Examples | Page cache? |
|---|---|---|
| Same for everyone | Homepage, shop page, categories, product pages | Yes, that's where the biggest gain is |
| Different per visitor | Cart, checkout, My account, the withdrawal form | Never |
If this goes wrong, a customer may see someone else's cart or even someone else's address. That's also a data breach; see Is this a data breach and do I need to report it?
What WooCommerce and LiteSpeed Cache already handle
WooCommerce itself marks the cart, checkout and My account pages as "do not cache", using a constant (DONOTCACHEPAGE) and no-cache headers. As soon as someone adds something to the cart, WooCommerce sets cookies such as woocommerce_items_in_cart, woocommerce_cart_hash and wp_woocommerce_session_. According to its own documentation, LiteSpeed Cache follows these WooCommerce rules. So for a regular shop, you don't need to add anything.
When you add your own exclusions
Exclusions are located under LiteSpeed Cache > Cache, tab Excludes:
- Do Not Cache URIs: addresses that should never be cached, one per line. Add these if you renamed the shop pages (for example
/cart/), if a translation plugin creates its own addresses (such as/de/warenkorb/), or for the withdrawal form under My account. - Do Not Cache Cookies: cookies that prevent a page from being served from cache. Be sparing here: a cookie that's present on every page disables caching for your entire site.
Also, don't add a second layer in front of this that caches everything. A CDN with a rule like "cache everything" ignores WooCommerce's headers; if you use one, exclude the shop pages and cookies there as well.
Object cache with Redis
Cart and checkout are always rebuilt from the database. An object cache stores frequently used database results in memory, which is especially helpful for a shop. Redis is included in Power Webhost Three, Power Webhost Four and Power Reseller. Enable Redis in DirectAdmin, enable the PHP extension redis, and in LiteSpeed Cache under Cache, tab Object, choose the Redis method with the path to the socket. All steps are described in Redis. If multiple sites in your package use Redis, give each site its own Redis Database ID.
Checking whether it's set up correctly
Open your site in a private window, press F12, choose the Network tab, reload the page and click on the first request.
- Homepage or product page, load twice: on the second load, you'll see
x-litespeed-cache: hit. - Cart, checkout and My account: no hit, but
x-litespeed-cache-control: no-cacheand acache-controlwithno-cache. - Add a product to the cart and open a product page: you'll see your own cart, not a stored version.
What caching doesn't solve
If your shop is still slow during busy periods, also check for an up-to-date PHP version, fewer plugins and WooCommerce's scheduled actions. A long list of failed actions slows down the database; see WooCommerce Status and Scheduled Actions: tracking down problems.
Further reading
- Free WordPress course, lesson 6.2 Caching
- LiteSpeed Cache: the settings of the Cache tab (English)
- WooCommerce: configuring caching plugins (English)
