• Hello There!

    I have difficulties to exclude an inline JS varable to be cached since it comes php.

    window.Yco.countryCode = '<?php echo $_SERVER['GEOIP_COUNTRY_CODE'] ?? ''; ?>';

    I placed the string based exludes to all boxes https://prnt.sc/3IO4iRzgpCNI even added this to the inline script data-no-optimize="1" data-no-defer="1" , but I have no luck whit it. If I disable the plugin, then it works.

    What do I do wrong?

    Thank you!

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support qtwrk

    (@qtwrk)

    the whole purpose of cache is to avoid php execution

    so if you do it PHP way , as that <?php echo , it just won’t work , as it is not executed again.

    you have 3 methods

    1. since you have GeoIP module already, you can enable GeoIP vary by add
    <IfModule LiteSpeed>
    RewriteEngine on
    RewriteRule .* - [E=Cache-Control:vary=%{ENV:GEOIP_COUNTRY_CODE}]
    </IfModule>

    this will save cache based on country code

    2. use javascript or something to call admin-ajax.php to get the country code

    3. use ESI, wrap your output in ESI block, more detail: https://docs.litespeedtech.com/lscache/lscwp/api/#generate-esi-block-url

    Thread Starter Milan Bartalovics

    (@bmilanyco)

    Thank you! The first sollution solved my issue.

    You have a point. We just started using LiteSpeed and LSCache and I didn’t had problems with this before on wp-rocket / nginx.

    Thank you, have a nice day!

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