• Resolved oanishchik

    (@oanishchik)


    I’ve cleared the cache several times and created a new one, including purging all, but all to no avail, the new scripts are ignored, they’re not added to the page cache, even though they’re present on the pages before/without caching. These scripts are not added to any exceptions. This includes the script that must be present on every page of the site, so it is not just a matter of some pages not being cached correctly. It’s about two scripts that were recently added to the functions.php. All scripts added to pages earlier via the same functions.php are cached perfectly.

    Here is an example of the script that is not cached (part of functions.php):

    function cmplz_hide_banner() {
    ob_start(); ?>
    <script>
    document.addEventListener("cmplz_before_cookiebanner", function() {
    cmplz_set_banner_status('dismissed');
    });

    </script>
    <?php
    $script = ob_get_clean();
    $script = str_replace(array('<script>', '</script>'), '', $script);
    wp_add_inline_script( 'cmplz-cookiebanner', $script);
    }
    add_action( 'wp_enqueue_scripts', 'cmplz_hide_banner', PHP_INT_MAX );

    Thank you!

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support litetim

    (@litetim)

    @oanishchik sorry for the problem you have
    I will make a test server and test the code. I will be back with and answer ??

    Plugin Support qtwrk

    (@qtwrk)

    it’s minified/combined

    if you want to see it in HTML directly , you may need to exclude it from optimization.

    Thread Starter oanishchik

    (@oanishchik)

    Thanks for the reply!

    Yes indeed, I see that the script is on every page as part of the minified js, also it comes last, which is correct. However, the script does not work, i.e. it does not do what it is supposed to do.

    I’m fine with the script being minified/combined. It should be.

    Plugin Support qtwrk

    (@qtwrk)

    well , first thing you need to make it works without being minified / combined , so does it work if you don’t minify/combine it ?

    Thread Starter oanishchik

    (@oanishchik)

    Absolutely,

    This script changes the cookie banner’s .cmplz-show class to .cmplz-dismissed, which causes the banner to be minimised when the page is visited. Without this script, the banner pops up and the visitor sees it. So, if you now open a cached version of any page, you will see the cookie banner, but if you open any page in a non-cached version, you will not see the cookie banner, but a tiny “banner”/button with three cookies on it, clicking on which reassigns the cookie banner’s .cmplz-show class, causing it to pop up.

    Plugin Support qtwrk

    (@qtwrk)

    you mean exclude this specific javascript from minify/combine , it works ?

    or you mean completely disable minify/combine ?

    Thread Starter oanishchik

    (@oanishchik)

    When I exclude the script from optimising (I added ‘cmplz_set_banner_status(‘dismissed’)’ to the JS Excludes and Guest Mode JS Excludes), everything works as it should, i.e. the script runs and does what it should. As an example, I purged and rebuilt the cache of page-id-40594.

    (I may also have misinformed you about what this script does. I think it just adds the “cmplz_banner-status” cookie with the value “dismissed” and everything else is a result of that).

    Plugin Support qtwrk

    (@qtwrk)

    if exclude it works, then please keep it excluded.

    I know it may not be the optimal solution , but unfortunately I think there is no way to make all and any javascript to work perfectly minified or combined. because when multiple script combiend , it could have conflict between them , and we won’t be able to rewrite these javascript, that’s why every page optm plugin have option to exclude JS/CSS or such.

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