lscache_wp icon indicating copy to clipboard operation
lscache_wp copied to clipboard

Updated plugin not showing up - review your cache validation mechanisms

Open binarykitchen opened this issue 7 months ago • 22 comments

Good evening,

The World Federation of Deaf contact page is broken: https://wfdeaf.org/contact/

It is based on Ninja Forms and Videomail plugins which was running fine a few weeks ago.

Customers are complaining, so I've manually released a new version of the Videomail plugin. Once they have updated it, it might work for them 🤷

Here's the commit which made a difference: https://github.com/binarykitchen/videomail-for-ninja-forms/commit/284201d4e55ff34137a3d5c8057aa47bc2b604c8

Although, I think this isn't right and is just a temporary fix. I do not want to rename the file each time I release.

Let's talk.

binarykitchen avatar Sep 02 '25 10:09 binarykitchen

Same URL + different content = enemy of caches.

szepeviktor avatar Sep 02 '25 12:09 szepeviktor

@binarykitchen If the issue is about the cached pages, you can simply fire a purge page via our API to clear it.

hi-hai avatar Sep 02 '25 14:09 hi-hai

If the issue is about the cached pages, you can simply fire a purge page via our API to clear it.

Hmm, how can I do that from my own WordPress plugin? Are there any examples? Thanks @hi-hai

binarykitchen avatar Sep 02 '25 22:09 binarykitchen

Same URL + different content = enemy of caches.

No @szepeviktor, it's always a different URL, the version is amended at the end with the wp_register_script function.

    wp_register_script(
      'nf-videomail-client',
      NF_Videomail::$jsUrl . 'videomail-client/index.min.js',
      array(),
      NF_Videomail::VERSION
    );

Generates URLs like this .../wp-content/plugins/videomail-for-ninja-forms/target/js/main.min.js?ver=8.0.3 Having version numbers should bust cache, and hence I believe it could be a bug with your plugin?

binarykitchen avatar Sep 02 '25 22:09 binarykitchen

Good evening gentlemen, are there any updates on this problem? It's happening again ...

binarykitchen avatar Sep 16 '25 06:09 binarykitchen

@binarykitchen just to make sure I understand correctly the right issue: even if update was done(version updated and amended to js file) it does not update on users sites. Am I right?

timotei-litespeed avatar Sep 16 '25 14:09 timotei-litespeed

Looking over the code I see:

wp_enqueue_script(
    'nf-videomail-main',
    NF_Videomail::$jsUrl . 'main.min.js',
    array('nf-front-end', 'nf-videomail-client'),
    NF_Videomail::VERSION
);

Is the dependency "nf-front-end" correct?

timotei-litespeed avatar Sep 16 '25 14:09 timotei-litespeed

@timotei-litespeed Nice find. I don't think this dependency is correct.

Would that break LiteSpeed's cache validation mechanism? If so, why are no warnings being printed nor logged?

binarykitchen avatar Sep 17 '25 07:09 binarykitchen

@binarykitchen Having same link for a resource when it changes it stops the cache from refreshing. I see CSS and JS links have module version added, so it's should work.

When CSS/JS minify/combine are turned ON, it might(not always) need Purge All - CSS/JS Cache to make sure the files are refreshed. Also browser cache plays a role in this.

timotei-litespeed avatar Sep 17 '25 07:09 timotei-litespeed

Thanks @timotei-litespeed we always amend the version and expect this to invalidate cache. Surprised why it's not happening?

When CSS/JS minify/combine are turned ON, it might(not always) need Purge All - CSS/JS Cache to make sure the files are refreshed.

How about an automatic purge all in your plugin when minified CSS and JS have changed, to be safe? Just an idea ... because most customers, business customers, don't know this field.

binarykitchen avatar Sep 17 '25 07:09 binarykitchen

@binarykitchen When the next release is scheduled to come out? After the release if you get tickets, please tell us the domain and we can look into. Or forward them to us directly by creating topic on https://wordpress.org/support/plugin/litespeed-cache/ or create ticket by sending email to support[at]litespeedtech.com.

If the solution is to clear CSS/JS we will help you with the code to do that.

timotei-litespeed avatar Sep 17 '25 11:09 timotei-litespeed

@timotei-litespeed I plan to release the next version of the https://github.com/binarykitchen/videomail-for-ninja-forms plugin soon, perhaps next week.

If you have ideas or even could provide a small PR to clear CSS/JS, that would be great.

An example domain where it is broken right now is https://wfdeaf.org/contact/ (just click on the tab "Send us a video message" and the plugin won't show up)

binarykitchen avatar Sep 17 '25 21:09 binarykitchen

@binarykitchen for now is not able to clear just CSS/JS But you can try: !class_exists('\LiteSpeed\Purge') || \LiteSpeed\Purge::purge_all(); after upgrade is done.

timotei-litespeed avatar Sep 17 '25 22:09 timotei-litespeed

Thanks for the advice. Where would you put this code? How does the plugin know it has been upgraded?

binarykitchen avatar Sep 17 '25 22:09 binarykitchen

I don't understand your question. I would add the code(in your plugin) where it's run only on update.

timotei-litespeed avatar Sep 17 '25 23:09 timotei-litespeed

@timotei-litespeed Thanks. Can you show me another example, another WordPress plugin, where the cache is being purged on update?

binarykitchen avatar Sep 17 '25 23:09 binarykitchen

@binarykitchen There is not a hook/action for check if updated. But you can save in DB the version of plugin and test on plugins loaded if the version from DB is the same as file. Take a look here: https://wordpress.stackexchange.com/questions/144870/wordpress-update-plugin-hook-action-since-3-9 At this moment, if version differ you can use the clear cache

timotei-litespeed avatar Sep 18 '25 12:09 timotei-litespeed

@binarykitchen WordPress does not have a standard method to check if the plugin has been updated for the purpose of running a plugin update routine. This has been the topic of much debate and, last I check, was left as "Will Not Fix".

As @timotei-litespeed mentioned, you can use the plugins_loaded hook and do a version compare of the current plugin version and the last stored version of the plugin. This is a very common technique used in plugins.

add_action( 'plugins_loaded', function() {

    // Get version information.
    $currentVersion = \NF_Videomail::VERSION;
    $lastRecordedVersion = get_option( 'NF_Videomail_Version' );

    // Check if current version is newer.
    if(version_compare( $currentVersion, $lastRecordedVersion, '>' )) {

        // Purge LiteSpeed cache.
        if(class_exists('\LiteSpeed\Purge')) {
            \LiteSpeed\Purge::purge_all();
        }

        // ...

        // Finally, update the stored version for future checks.
        update_option( 'NF_Videomail_Version', $currentVersion );
    }
});

kjohnson avatar Sep 22 '25 01:09 kjohnson

@kjohnson that's the code :)

@binarykitchen is there something I can help you with? If the issue is resolved, please close the issue :)

timotei-litespeed avatar Sep 22 '25 12:09 timotei-litespeed

@timotei-litespeed Please don't close it yet. I will do a new release and ask my customers to update. Once it's back working, then I will let you know, and we can close it.

But there is one thing I am still confused about: I already amend the version number to the URL. Why isn't this busting litespeed's cache? Perhaps there is still some bug on your side?

binarykitchen avatar Sep 22 '25 23:09 binarykitchen

@binarykitchen I will wait for your feedback :) There are a few things that can create problem: browser cache OR LSC settings CSS/JS minify and combine that create static files that needs refresh

timotei-litespeed avatar Sep 23 '25 06:09 timotei-litespeed

Thanks @timotei-litespeed

I think it's perhaps also related to this new bug I just raised in a separate ticket: https://github.com/litespeedtech/lscache_wp/issues/908

binarykitchen avatar Sep 23 '25 06:09 binarykitchen