Support » Plugin: LiteSpeed Cache » Developer question related to cookies

  • Resolved Sibin Grasic


    Hello, I’m the developer of SrbTransLatin plugin (

    I use a cookie to serve two different versions of the same page (cookie: stl_script). One is in Cyrillic, one is in latin.

    Can I use vary_add somewhere in my code so LScache can cache two different versions of the page? In Cyrillic and in latin?

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hai⚡


    I am planning to add the vary cookie to setting, and give a new API in about v3.1 or v3.2. For now, please try the following codes and see if it works or not:

    add_filter( 'litespeed_vary_cookies', function( $cookies ) {
    	$cookies[] = 'stl_script';
    	return $cookies;
    } );

    I have a similar situation. I’m using a cookie to serve different versions of the same page. I tried your solution @hailite, but it’s not working correctly.

    The vary header is included, but only when cache is not hit:

    x-litespeed-cache: miss
    x-litespeed-vary: cookie=next_lan
    x-turbo-charged-by: LiteSpeed

    If the cache is hit, the vary header is nowhere to be found:

    x-litespeed-cache: hit
    x-turbo-charged-by: LiteSpeed

    It’s almost acting like a “passive” don’t cache certain cookies setting, meaning if for some reason the cache is not hit on some page (regardless of having the cookie), the x-litespeed-vary header will be included, but not otherwise.

    I get the same issue when using;

    add_action('init', function() {
       if (method_exists('LiteSpeed_Cache_API', 'vary_add')) { 

    I’m also using Cloudflare, don’t know if that affects cookies though.

    Plugin Support qtwrk



    when you have cache hit , other header like x-litespeed-tag , x-litespeed-vary will be dropped and not shown to user.

    Could you please check on the content instead of header to verify if vary works or not ?

    Best regards,

    The content(a banner) didn’t appear when the cache was hit, only when missed. I did get it to work by editing .htaccess though:

    ### marker LOGIN COOKIE start ###
    RewriteRule .* - [E="Cache-Vary:wp-postpass_124e250c9dfea8eoe63758772526411e,next_lan"]
    ### marker LOGIN COOKIE end ###

    Now when I have the cookie set in my browser, the banner actually shows and cache hits as x-litespeed-cache: hit,private.

    I know this is not the best practice because it’s within ## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##.

    How can I use it outside this block? Should I just include the following line: RewriteRule .? - [E=Cache-Vary:next_lan] outside the block by it’s own? Or maybe outside, but wrapped in <IfModule LiteSpeed> tags?

    I don’t know why the other methods didn’t work for me, maybe the headers where overriden or had some conflict with another plugin.

    • This reply was modified 1 month, 3 weeks ago by wenape.
    • This reply was modified 1 month, 3 weeks ago by Yui.
    Plugin Support qtwrk



    Please try move it out from LScache marker , I think it should still work

    Best regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.