Custom ESI questions + polylang issue
-
Hey im using bricks builder on my site and would like to render some blocks with esi, as i have these blocks on nearly all my pages and dont want to purge those whenever only this block content changes. As im using polylang aswell i need to obviously have different “translations” for the blocks in those different languages.
My current approach is to load an esi block via the litespeed_esi_url filter depending on the “template id” i provide in my custom function ( this id is the internal bricks template for that section / block ). On the frontend i am then loading that function together with the needed css + js files which seem to not load via the esi block ( i assume it only caches the pure html and does not execute all the other stuff that is loaded via that template ( see bricks builder / includes / templates.php )
My code at this stage:
add_action('litespeed_esi_load-best_mouse_top5_de', 'best_mouse_top5_de_esi_load');
add_action('litespeed_esi_load-best_mouse_top5_en', 'best_mouse_top5_en_esi_load');
function best_mouse_top5_de_esi_load($params) {
do_action( 'litespeed_control_set_ttl', 5 );
echo do_shortcode('[bricks_template id="' . $params['id'] . '"]');
do_action('litespeed_debug2', '[Best Mouse Top 5 DE] - Rendered template id: ' . $params['id']);
}
function best_mouse_top5_en_esi_load($params){
do_action( 'litespeed_control_set_ttl', 5 );
echo do_shortcode('[bricks_template id="' . $params['id'] . '"]');
do_action('litespeed_debug2', '[Best Mouse Top 5 EN] - Rendered template id: ' . $params['id']);
}
function load_custom_esi($template_id) {
$esi_status = apply_filters( 'litespeed_esi_status', false );
if ($esi_status) {
switch ($template_id) {
case '4002':
echo apply_filters('litespeed_esi_url', 'best_mouse_top5_de', 'Best Mouse Top 5 DE ESI Block', array('id' => $template_id), 'public', false, false, true, false);
break;
case '4698':
echo apply_filters('litespeed_esi_url', 'best_mouse_top5_en', 'Best Mouse Top 5 EN ESI Block', array('id' => $template_id), 'public', false, false, true, false);
break;
}
} else {
echo do_shortcode('[bricks_template id="' . $template_id . '"]');
}
}On the main language (‘de’) everything works fine, but on the translated page (‘en’) the block is empty and the Cache-Control + Tags are missing aswell.
de:
<!-- Block cached by LiteSpeed Cache 6.5.0.2 on 2024-09-21 15:52:11 -->
<!-- X-LiteSpeed-Cache-Control: public,max-age=5,esi=on -->
<!-- Full varies: guest_mode:1+webp -->
<!-- X-LiteSpeed-Tag: b79_HTTP.200,b79_ESI,b79_ESI.best_mouse_top5_de2,b79_W.template-4002,b79_ -->
en:
<!-- Block cached by LiteSpeed Cache 6.5.0.2 on 2024-09-21 15:39:18 -->
<!-- X-LiteSpeed-Cache-Control: public,max-age=604800,esi=on -->
<!-- Full varies: guest_mode:1+webp -->
<!-- X-LiteSpeed-Tag: b79_HTTP.200,b79_HTTP.301,b79_ -->
Is this a bug or am i doing something wrong? – You can check the behaviour on my frontpage debug is active at this time
Furthermore i got a question, as these 2 blocks basicly have the same content ( apart from the translations ) is it possible to just have 1 ESI block with some sort of unique identifier to distinguish between the languages. Maybe a tag like custom-esi-“ID”-“LANGPARAMTER”. If yes how would this have to be implemented? And how can i then purge that specific block with the associated unique id / tag if this is possible.
Regards & thanks for your help
Andre
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.