Strange ESI behaviour. ESI returning empty string and forcing caching policy
-
Hi there,
Our website is using ESI with a no-cache policy to keep a live counter updated on our websites homepage. A few weeks ago we noticed some strange behaviour where the counter completely disappeared and the ESI block comments specified that the block was being cached and not respecting the no-cache policy. We immediately recognised that something had gone wrong with the ESI implementation that kept the live impact counter up to date. Running Purge All resolved the issue but it broke again within a few hours.
We then pushed a hotfix that disabled ESI for the frontend visitors by dumping the value out that would normally be ESI but wrapped the old ESI system in a “display: none” so we could use inspector to view what the ESI value was doing.
The code for this has been documented below.function wil_front_page_collective_impact_figure( ) { // HOTFIX Circumvent ESI due to bug echo _wil_front_page_collective_impact_figure(); // Add ESI implementation but wrap in hidden for debugging purposes if( apply_filters( 'litespeed_esi_status', false ) ) { echo apply_filters( 'litespeed_esi_url', 'wil_front_page_collective_impact_figure', 'Impact Metrics Block' ); } } add_action( 'litespeed_esi_load-wil_front_page_collective_impact_figure', '_wil_esi_front_page_collective_impact_figure' ); function _wil_esi_front_page_collective_impact_figure() { do_action( 'litespeed_control_set_nocache' ); ?> <span class="d-none"> <?= _wil_front_page_collective_impact_figure(); ?> </span> <?php } function _wil_front_page_collective_impact_figure() { // Outputs the current impact figure ... }
This implementation meant that we could debug the ESI issue in production as this is our only way of reproducing the error without affecting our experience for our end users (Apart from the live counter only updating daily). After deploying the hotfix we could see the current impact figure alongside the ESI impact figure using the chrome inspector and the ESI block for the hidden impact figure was working correctly.
After checking back 1 day later it was once again broken, displaying an empty value and ignoring our no-cache policy on that ESI block.
Screenshot detailing an unspecified caching policy and an empty ESI blockWe then noticed that purging the cache seemed to fix the issue where ESI for that block would start working again.
Screenshot detailing the working ESI caching policy and displaying a non-empty ESI blockThe issue here is that after a couple hours ESI stops working again, defaulting back to an unspecified caching policy and empty block content and we don’t know why. I’ve worked with litespeed ESI for a previous job with a different company in the past and encountered similar issues so I’m not 100% confident this issue isn’t just isolated to us (or I could just be the common denominator). Any help would be appreciated here.
Report number:?IKHBRDLF
Report date:?10/31/2023 07:32:27
- The topic ‘Strange ESI behaviour. ESI returning empty string and forcing caching policy’ is closed to new replies.