How to Bypass Caching of AI Chatbot Widget

Good Day!

Background: Currently, our website uses both Cloudflare APO and FlyingPress.

Issue: Both Cloudflare APO and FlyingPress are caching our website’s pages, so when I disable Elfsight’s AI Chatbot in the backend (say, for site testing and to prevent burning through our widget’s credits), the widget still loads (i.e., appears) on our website pages.

Request: Is there a PHP and/or JS code I can use to ensure Elfsight’s AI Chatbot widget is never cached by Cloudflare and/or FlyingPress?

Note: Since the AI Chatbot widget is installed on all our website’s pages, disabling caching on all of our pages is not an option. In short, I am looking for a code that will prevent the widget from being cached.

Thank you!

1 Like

Hey there, @AeroConsultants :waving_hand:

Please try to reinstall the widget using this code and let me know if it helped :slightly_smiling_face:

<script src="https://elfsightcdn.com/platform.js" async></script>
<script>
    (() => {
        const WIDGET_ID = "elfsight-app-9019baa4-6ea8-4e64-9856-5eab9dc16b55";

        const installWidget = () => {
            const widget = document.createElement("div");
            widget.classList.add(WIDGET_ID);
            document.body.append(widget);
        };

        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', installWidget);
        } else {
            installWidget();
        }
    })();
</script>
2 Likes

Hi @Max!

Welcome back. Thank you. Testing now. Stay tuned.

Cheerio!

1 Like

Update: Unfortunately, the code did not work. Tried many test configurations. The widget is still being cached.

Test Configurations:

  1. FlyingPress ON - Cloudflare OFF
  2. FlyingPress OFF - Cloudflare ON
  3. FlyingPress ON - Cloudflare ON

Note: For all of the above cases, “platform.js” was excluded from Delay, Deferral, and Minification.

At this point, testing halted since I’m burning through our “View Count” credits. It would be nice if Elfsight found a way to allow customers to test their widgets without penalizing their “View Count” credits.

Last, if you decide to review and adjust the code you provided, please re-verify it’s compatible and works with Cloudflare and all major caching plugins.

1 Like

Ah, I see, and I am really sorry about that!

To investigate this issue, we’ll need temporary access to your website’s backend. Here is an article explaining how you can share it - Providing access to your WordPress website - Elfsight Help Center.

Please let me know once it’s shared and we’ll start working on it :slightly_smiling_face:

1 Like

Thank you, @Max!

As soon as our “View Count” credits are refreshed, I’ll conduct more testing. If additional testing does not help, I will share our website’s login credentials as you instructed.

Meanwhile, can you confirm your developers tested their code with no issues? (using Cloudflare and a caching plugin).

This is what I did (testing steps):

  1. Installed widget on our website using the code you provided (via WPCode, HTML code snippet, loaded before the /body). Widget successfully loaded on all website pages.
  2. Allowed FlyingPress to preload our website pages.
  3. Allowed Cloudflare to cache our website pages.
  4. Widget loaded successfully on all website pages.
  5. Disabled the HTML code snippet noted in 1. above.
  6. Widget still appeared on all website pages (widget still cached). Note: The only way to make the widget disappear was to clear all cache from FlyingPress and Cloudflare.

Here’s another reason for my request: The code snippet I created in 1. above, also has a conditional logic that tells the widget to display on our website only during weekdays, not weekends. Due to caching of your widget, the conditional logic did not work either.

I hope the above helps.

Cheers!

1 Like

Ah, I see what you mean, thanks for providing more details.

It seems that the solution we’ve shared doesn’t fully meet your specific case. To check if it’s possible to make the conditional display logic work fine with the plugins mentions, we’ll need the access to the website’s backend.

If you could share it with us, our devs would be happy to investigate right away (Worry not - the views from the Elfsight staff aren’t added to your views count) :slightly_smiling_face:

1 Like

Will do! Will reach out later this week. So, based on your reply, what exactly does your code accomplish?

Edit: Never mind, I queried Gemini and got my answers. Also, Gemini provided two potential solutions to solve my issues. Hint: Cache Busting! Will test and report back soon.

1 Like

Update: I tried 6 different cache-busting methods, none of them worked. So, I will reach out to Team Elfsight later this week or next. However, please don’t wait for me! If you can develop a tested, confirmed solution beforehand, pleasae share it.

Note: Please keep in mind that when a caching plugin such as WP Fastest Cache or FlyingPress “preloads” or “preheats” website pages – combined with Cloudflare’s aggressive caching – it will be nearly impossible to instantly bypass caching of the AI Chatbot widget.

1 Like

Unfortunately, it’s hard to find a working solution without access, but as soon as you share it with us, our devs will start investigating it :slightly_smiling_face:

1 Like