Wordpress LScache Plugin: is it possible to prevent Litespeed Cache from caching a section of PHP-generate
Last Updated on: Wed, 15 Apr 2026 00:00:02 In a WordPress theme footer, I have PHP code to output a random 1 of 3 different tags (to display 1 of 3 different modal lead forms). The problem is that Litespeed Cache caches the outputted in the HTML, and repeated page loads do not generate a different random modal lead form. The PHP code worked before turning Litespeed Cache on so I know that Litespeed Cache is the cause. Is there a way to tell Litespeed Cache to ignore a section of PHP? (the PHP which outputs a random 1 of 3 s Hi @insightdes, You can try to use ESI feature to generate dynamic content in the cached file, here are the introduction and example: https://blog.litespeedtech.com/2017/09/06/wpw-esi-and-litespeed-cache/ https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:esi_sample For this situation, I think making it non-cacheable is not a good solution. That way will make the visit to your WP always hit WP which equals no cache on main page. Its more like a case out of cache scope. A better way is to keep cache copy the same, but use JS to random call script tags. Thanks @hailite, How would I use JS to do random call script? I have: var min=1 var max=3 var random = Math.random() (+max - +min) + +min switch ($random) case 1: document.write([script 1]) break Except the document.write([script 1]) where [script 1] is the normal tag doesnt work. Help appreciated. Hi @insightdes, You can try below script if you are using jQuery var randomnos = Math.ceil(Math.random() 1000000000) var mysource = https://www.example.com/myjsfile. +randomnos+ .js window.onload = function() $.getScript(mysource,function() console.log(loaded) ) or below pure JS script: var randomnos = Math.ceil(Math.random() 1000000000) var mysource = https://www.example.com/myjsfile. +randomnos+ .js window.onload = function() var script = document.createElement(script) script.src = mysource document.head.appendChild(script) Thank you kindly @stanleylitespeed. The has some custom parameters: Please try var randomnos = Math.ceil(Math.random() 1000000000) var mysource = https://www.example.com/myjsfile. +randomnos+ .js window.onload = function() var script = document.createElement(script) script.src = mysource script.setAttribute(data-opf-params, test)
LiteCache Rush: Speed comes from using less, not from doing it faster
Reference