Full-page caching breaks down the moment a page contains user-specific content — a mini-cart showing item count, a “Hello, Marie” greeting, a login/logout toggle. The standard fix is to exempt the entire page from cache, which throws away most of the performance benefit. LiteSpeed Cache for WordPress solves this with Edge Side Includes (ESI): the main page body is cached normally, while specific blocks are flagged as dynamic and assembled per-request from separate sub-requests. This article explains how LSCWP ESI works, how to enable it, and how to wrap a widget or block in an ESI hole correctly.
How to verify
# Confirm ESI is enabled on the server (LSWS must support it)
curl -sI https://example.com/ | grep -i 'x-litespeed-cache-control\|esi'
# Check ESI status via WP-CLI
wp eval 'echo defined("LSCWP_ESI_ENABLE") && LSCWP_ESI_ENABLE ? "ESI enabled" : "ESI disabled";'
wp eval 'echo LiteSpeed_Cache_API::esi_enabled() ? "LSCWP ESI on" : "LSCWP ESI off";'
# Inspect raw HTML of a cached page for ESI include tags
curl -s https://example.com/ | grep -i 'esi:include\|<esi:'
# Confirm the ESI sub-request is served correctly
curl -sI 'https://example.com/?lsesi=widget_id&_lscache_esi=1' \
| grep 'x-litespeed-cache'
# Check LSWS version supports ESI (5.0+)
/usr/local/lsws/bin/lshttpd -v | head -1
What’s happening
ESI is a W3C specification for assembling pages from independently cached fragments. LiteSpeed Web Server has native ESI support: when it sees an <esi:include src="..." /> tag in a cached HTML response, it makes a sub-request for the indicated URL, substitutes the returned HTML in place of the tag, and delivers the assembled page to the browser. Each fragment can have its own TTL and its own cache vary rules, independent of the parent page.
LSCWP implements ESI on top of this mechanism for WordPress. When you mark a widget or a block as ESI-enabled, the plugin renders an <esi:include> tag where that widget would normally appear, and registers a separate WordPress route (?lsesi=widget_id) that returns just the widget HTML. The main page is cached as a static HTML file with the ESI hole intact. When LSWS serves that page, it fires the sub-request, which PHP handles, and stitches the result back in.
The practical outcome: a WooCommerce product archive page with 80,000 monthly visits can be fully cached even when the site has logged-in users, because the mini-cart widget and the login/logout toggle are ESI holes. LSWS serves the cached body at memory speed, fires one lightweight sub-request per ESI hole, and the browser receives a fully assembled page. The PHP cost goes from O(page request) to O(ESI hole count), which on a page with two ESI holes means two small PHP invocations instead of one large one — and those invocations are usually cacheable themselves at a per-user private cache level.
ESI works only when LiteSpeed Web Server is the origin. It does not work with Nginx, Apache, or when you are sitting behind a Varnish or Cloudflare layer that does not support ESI assembly. If you are using LSWS, ESI is enabled by default since LSWS 5.0; you only need to activate it in LSCWP.
The procedure
Step 1 — Enable ESI in LSCWP.
Go to LiteSpeed Cache → Cache → Advanced and set Enable ESI to On. Save changes. The plugin will now activate the ESI route (?lsesi=) and begin rendering ESI tags for marked widgets.
Step 2 — Mark widgets as ESI-aware in LSCWP.
Go to LiteSpeed Cache → ESI. The ESI configuration page shows registered widget types. Enable ESI for:
- WooCommerce cart widget — mark as Private (per-user)
- Login/logout widget — mark as Private
- Recent comments widget — mark as Public with a short TTL (e.g., 300 seconds)
Widgets marked Public share one cached fragment for all logged-out visitors. Widgets marked Private generate a per-user cached fragment. Use Private only where truly necessary — each Private ESI hole multiplies the sub-request count by active user count.
Step 3 — Register a custom ESI block in PHP (for theme or plugin developers).
If you have a custom PHP widget or block that must be dynamic, wrap it with the LSCWP ESI API:
// In your plugin or functions.php
add_action( 'init', function() {
// Register a custom ESI block identified by 'my_greeting'
LiteSpeed_Cache_API::register_esi( 'my_greeting', array(
'public' => false, // private per-user
'ttl' => 600, // seconds
'vary' => array( 'user_id' ),
) );
} );
// Hook the ESI output callback
add_action( 'litespeed_esi_load-my_greeting', function() {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
echo '<span class="greeting">Hello, ' . esc_html( $user->display_name ) . '</span>';
} else {
echo '<a href="' . wp_login_url() . '">Sign in</a>';
}
} );
In your template, output the ESI hole with:
LiteSpeed_Cache_API::esi_output( 'my_greeting', 'My Greeting Block' );
LSCWP renders this as <esi:include src="/?lsesi=my_greeting&..." /> in the cached HTML.
Step 4 — Validate ESI assembly in the browser.
Load the page in a browser and inspect the network panel. You should see:
- One main page request returning the cached HTML frame (very fast,
X-LiteSpeed-Cache: hit) - No separate XHR requests for the ESI fragments — they are assembled server-side before the response is sent
Check the HTML source for absence of <esi: tags: if the browser receives raw ESI tags, LSWS is not assembling them, which usually means ESI is disabled at the vhost level.
Step 5 — Purge ESI fragments when underlying data changes.
ESI fragments are cached independently, so purging the parent page does not automatically purge its ESI holes. Use the LSCWP API:
// Purge a specific private ESI fragment for a user
LiteSpeed_Cache_API::purge_esi( 'my_greeting', $user_id );
// Purge all ESI fragments of a type
LiteSpeed_Cache_API::purge_esi_all( 'my_greeting' );
For WooCommerce, LSCWP handles cart fragment purges automatically when orders are placed or cart contents change, provided the WooCommerce integration is active.
Common pitfalls
ESI tags appearing in browser source. This means LSWS received the page from PHP with ESI tags but did not assemble them before forwarding to the browser. Check that LSWS ESI processing is enabled at the vhost level in /usr/local/lsws/conf/httpd_config.conf — look for enableESI 1 in the relevant virtual host block. If you are behind a Cloudflare proxy with HTML minification active, Cloudflare may be stripping the ESI tags before LSWS can read them on origin requests.
Private ESI causing excessive PHP load. Each page load for a logged-in user fires one PHP sub-request per Private ESI hole. On a high-traffic site with 5,000 concurrent logged-in users and 3 Private ESI holes per page, that is 15,000 PHP sub-requests per page-load cycle. Use Private ESI sparingly; consider whether a short-TTL Public ESI fragment (e.g., 60 seconds) is sufficient for your use case.
WooCommerce mini-cart shows stale count after add-to-cart. If the cart widget ESI fragment is cached with a TTL and a visitor adds an item, the ESI fragment will not update until the TTL expires or a purge fires. LSCWP should fire the purge automatically via the WooCommerce add-to-cart hook, but custom AJAX add-to-cart implementations that bypass WC_Cart may not trigger it. Verify by checking the woocommerce_add_to_cart action hook in your theme.
ESI sub-requests blocked by security plugin. Some security plugins reject requests with ?lsesi= query parameters as suspicious. Add lsesi to your security plugin’s query string whitelist, or configure the firewall rule to allow requests from 127.0.0.1 unconditionally.
ESI not working after moving to a new host. ESI requires LSWS as the web server. If you migrate to a host running Nginx or Apache with the LiteSpeed module (mod_lscapi), the <esi:include> tags will not be assembled. ESI assembly requires the full LiteSpeed Web Server binary, not the Apache plugin.
ESI configuration sits at the intersection of server, plugin, and application code — getting it right across a custom WordPress theme takes an operator who understands all three layers. Stack Harbor’s managed operations team handles LSCWP ESI setup and monitors sub-request latency as part of our standard LiteSpeed environment tuning.