• Resolved David Aguilera

    (@davilera)


    Hi there!

    I’m one of the developers behind Nelio A/B Testing, a split testing solution for WordPress. We’re interested in improving our compatibility with LiteSpeed Cache and, in particular, its dynamic caching capabilities.

    In its current form, our plugin loads alternative content by appending an extra query arg in a tested URL via a JavaScript redirection. That is, if a visitor lands on https://example.com/tested-page/, our plugin will redirect them to https://example.com/tested-page/?nab=X, where X is the variant they’re supposed to see (0 is variant A, 1 is variant B, etc).

    We’re currently working on a new version of the plugin where, instead of loading alternative content based on the query arg, the web owner might decide to load alternative content based on the value of a certain cookie (i.e. nabAlternative).

    I looked at your source code (more specifically, your third-party integrations) and noticed you provide (I think) two filters for that (litespeed_vary_cookies and litespeed_vary_curr_cookies). If I add the following snippet in our plugin:

    function add_nab_alternative_as_dynamic_cookie( $cookies ) {
      if ( ! is_cookie_testing_enabled() ) {
        return $cookies;
      }//end if
      $cookies[] = 'nabAlternative';
      return $cookies;
    }//end add_nab_alternative_as_dynamic_cookie()
    add_filter( 'litespeed_vary_curr_cookies', __NAMESPACE__ . '\add_nab_alternative_as_dynamic_cookie' );
    add_filter( 'litespeed_vary_cookies', __NAMESPACE__ . '\add_nab_alternative_as_dynamic_cookie' );

    would things work as expected?

    I also have a few more questions that I’d like you to address:

    1. Should we add the aforementioned code in our plugin to make Nelio compatible with LiteSpeed? Or would it be better if you make yours compatible with ours?
    2. If a visitor lands on a tested page and they don’t have a nabAlternative cookie yet, how does your plugin behave? Is the cache bypassed and WordPress runs on its own?
    3. I’ve seen other cache plugins create a special config file which we need to regenerate when toggling on/off the setting to enable cookie-testing in Nelio. Is that also necessary in LiteSpeed?

    Thanks!

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

    (@qtwrk)

    thanks for reaching us , I think it would best and simplest as add belwo rule at top of .htaccess

    <IfModule LiteSpeed>
    RewriteRule .? - [E="Cache-Vary:your_cookie_name"]
    </IfModule>

    if you want to do by php code , you can use

    add_filter( 'litespeed_vary_cookies', function( $list ) { $list[] = 'your_cookie_name'; return $list; } );

    but this action will require user to go to our plugin setting page , click “save”, to trigger the generation of new vary rule into .htaccess by our plugin

    that’s why I think it would be simpler if you can directly add above rewrite rule at top of .htaccess, one less step for users to do.

    ———–

    if cookie is not set, it will be treated as empty value , for example on same page URI , /something/

    it will display different cases with cookie as :

    case 1 , cookie is not set

    case 2 , cookie value is set to X

    case 3, cookie value is set to Y

    case 4 , cookie value is set to Z

    and so on

    Plugin Support litetim

    (@litetim)

    Hello David.

    Thank you for contacting us and make our products compatible with each other.

    I’ll try yo answer your questions as good as possible.
    1) We would ask you to add third party integrations in your plugin. It’s easier for you to keep track of changes.
    2) It will show a cached version of page. Depending on the accessed version.
    3) If cache is on will server a cached version of link(vers A OR vers B), depending on the cookie. LiteSpeed server will create the vary, save data and use it when needed.

    For furthers inquires please create a ticket on email: support at litespeedtech.com and we will try to help as soon as possible.

    Thank you,

    Tim

    Thread Starter David Aguilera

    (@davilera)

    Thanks @qtwrk and @litetim for your answers.

    Questions to @qtwrk:

    if you want to do by php code , you can use […] but this action will require user to go to our plugin setting page , click “save”, to trigger the generation of new vary rule into .htaccess by our plugin

    Well, I’d rather have my users click on a button in the UI than tweaking with config files on their server.

    Just a couple more questions:

    1. Why only litespeed_vary_cookies instead of both litespeed_vary_cookies and litespeed_vary_curr_cookies? What’s the latter filter for? I see some third-party built-in integrations (like, for example, thirdparty/aelia-currencyswitcher.cls.php) use it.
    2. Your snippet is quite similar to mine, but you didn’t include the if condition. Can I safely use it?
    3. Can I programmatically trigger the Save action to generate (depending on the if in 2) proper vary rules in .htaccess?

    Questions to both of you:

    I tried to test the plugin locally (I’m using Lando) but I get the following warning message:

    LSCache caching functions on this page are currently unavailable!

    To use the caching functions you must have a LiteSpeed web server or be using QUIC.cloud CDN.

    and I have no idea how to try out my code. How should I proceed?

    Plugin Support qtwrk

    (@qtwrk)

    yes, sorry I was wrong

    it should be like

    add_filter('litespeed_vary_curr_cookies', 'lscwp_add_custom_cookie'); 
    add_filter('litespeed_vary_cookies', 'lscwp_add_custom_cookie');
    function lscwp_add_custom_cookie($list){
        $list[] = 'test1_cookie'; 
        return $list; 
    }

    and with first one , you don’t need to re-trigger the .htaccess generation

    ————

    yes , it was quick demo , you should if it before insert your cookie

    ——-

    with this code , you don’t need to trigger it , but just need to do a purge all, so to make cookie vary effect

    ———

    yes, our plugin requires LiteSpeed webserver for caching

    please create a ticket by mail to support at litespeedtech.com with reference link to this topic , I can arrange something for you

    Thread Starter David Aguilera

    (@davilera)

    Done, thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Caching Filters for Plugin Developers’ is closed to new replies.