Please note that the LiteSpeed Cache plugin does not set the Cache-Control header. This header is typically generated by WordPress core, not by the LiteSpeed Cache plugin.
Instead, the LiteSpeed Cache plugin adds the x-litespeed-cache response header, which indicates the cache status of the page:
x-litespeed-cache: hit — The page was served from the cache.
x-litespeed-cache: miss — Was not cached, but the next request will be the cache hit
if you are looking to verify whether a page is being cached by LiteSpeed Cache, the x-litespeed-cache header is the appropriate indicator rather than the Cache-Control header.
Thank you for your explanation.
The reason I’m asking about the Cache-Control header is that my CDN relies on it to determine whether HTML pages should be cached.
I need a Cache-Control: public header to be sent for non-logged-in visitors so that my CDN can cache public HTML pages. For logged-in users, Cache-Control: no-cache is perfectly fine.
Is there any way to configure LiteSpeed Cache to send a Cache-Control: public header for guest visitors, or do you recommend another approach to achieve this?
Thank you.
Is there any way to configure LiteSpeed Cache to send a Cache-Control: public header for guest visitors
Unfortunately, No as I mentioned LiteSpeed cache do not add or handle this cache header at all.
You can check with your hosting provider for more help on this.
As my colleague @asfly told you this is not something we can modify from admin.
You can use this code:
add_action(
'litespeed_control_finalize',
function ( $esi_id ) {
if ( $esi_id || is_admin() || headers_sent() ) {
return;
}
if ( defined( 'DONOTCACHEPAGE' ) && apply_filters( 'litespeed_const_DONOTCACHEPAGE', DONOTCACHEPAGE ) ) {
return;
}
if ( ! \LiteSpeed\Control::is_cacheable() || \LiteSpeed\Control::is_private() ) {
return;
}
if ( \LiteSpeed\ESI::has_esi() ) {
return;
}
$value = apply_filters( 'litespeed_cdn_cache_control_value', 'public' );
if ( $value ) {
header( 'Cache-Control: ' . $value );
}
},
10,
1
);
But use it on your own risk.
If you need help in the future, please make us aware that you use this code.
Hello,
Thank you very much for your help.
This completely solved my problem. With this code, I can now control my site’s HTTP response headers and send the Cache-Control header to my CDN.
Thanks again for your support!