How to prevent Page Content Javascript from being cached?

Hi

I’m using the cache plugin WP Fastest Cache and so far it worked but recently I noticed that it’s been blocking the javascript that I added to the pages in the editor. There is an option in the cache plugin to exclude javascript files from being cached. Is the code that I’m adding in the page editor saved in a certain file on my WP directory so I can exclude it or where is it saved?

I hope you can help. Best regards,
Dennis

Hi Dennis,

Thanks for reaching out.
The code you have added to the specific page is been integrated as a script into the page, not as a different file. So if you want that not be cached, you need to add that specific page to the exclude list from the plugin settings or you can contact the plugin author on this.
You can get more information on how to exclude the page from the below articles:

  1. https://www.wpfastestcache.com/features/exclude-page/
  2. https://blogaid.net/wp-fastest-cache-settings/

Hope it helps.
Thanks

Thanks for your reply. I know how to exclude pages and javascript files and I contacted the author of the app for further assistance. He told me to add this code to the script tag in the javascript:

script data-wpfc-render=“false”

This code will prevent only this part of the javascript to be cached. But the theme automatically adds the script tag that is added through the editor, is that correct? Do you know how I can modify the script tag from the content page javascript with this or is it just not possible with the editor?

THanks very much in advance!
Dennis

Hi Dennis.

Regretfully, there is no such option to add that specific code to the script tag loaded through the Global or Element JavaScript, although you can try by adding the following code which will add the specific code into all of the ** scripts** that loads with the external JavaScript files.

if(!is_admin()) 
{
    function add_asyncdefer_attribute($tag, $handle) 
    {
            if ( FALSE === strpos( $url, '.js' ) ) return $tag;
            if ( strpos( $url, 'jquery.js' ) ) return $tag;
            return str_replace( 'script type="text/javascript" ', 'script data-wpfc-render="false" ', $tag );
    }    
    add_filter('script_loader_tag', 'add_asyncdefer_attribute', 10, 2);
}

Remember that the above code will work if copied as it is and don’t conflict with any existing style.
Please note that the code provided serves only as a guide to help you get started custom coding on your own if there’s no option offered in our theme or the products we bundle.
We do not provide support for custom codes that means we can’t fix it in case it conflicts with something on your site nor will we enhance it.

Thanks

This works great! Thank you!

Hi Dennis,

Glad that we are able to help you.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.