• Hello,

    I am using WordPress with the LiteSpeed Cache plugin.

    I noticed that when users are not logged in, LiteSpeed Cache does not send a public Cache-Control header. However, when a user is logged in, it sends:

    Cache-Control: no-cache

    I would like to know why the public cache control header is not being sent for non-logged-in users and how I can configure LiteSpeed Cache to send a public Cache-Control header for cached pages.

    Could you please advise what settings I should check or change?

    Thank you.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.

    Thread Starter kasra naraghi

    (@gamefa)

    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.

    Plugin Support litetim

    (@litetim)

    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.

    Thread Starter kasra naraghi

    (@gamefa)

    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!

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.