• Hi,
    i am useing the plugin autoptimize https://ww.wp.xz.cn/plugins/autoptimize/

    So first i have to put the front.css to the exceptions. otherwise the cookie notice bar isn not shown.

    But the other problem is, when the cookie for accepting is set and after reload the function in your plugin cookie_setted() becomes true the js and css are not load. That is good for save loading code. But inline js, from a post or page or an file like footer.php, is not working after this.

    Maybe this should be solved or have you another hint for me?
    At the moment changed the line 720 in the cookie-notice.php with a # to make the front.css and front.js to be loaded always.

    Best regards,
    Harry

Viewing 6 replies - 1 through 6 (of 6 total)
  • Same problem here, would suggest an option “load always js/css” for better compatibility with caching and/or minimizing plugins.

    Any plans to fix this in near future? Don’t want to “hack” plugin-files after each update. 🙁

    In case anybody is interested in the “hack”, our solution at the moment is a custom added filter in file cookie-notice.php lines 719+

    /**
     * Checks if cookie is setted
     * 
     * @return bool
     */
    public function cookie_setted() {
    	return apply_filters( 'cn_cookie_setted', isset( $_COOKIE[self::$cookie['name']] ) );
    }

    In theme functions.php we use that filter and set it to false if cache/autoptimize/.. is in use, simplified example:

    function my_cn_cookie_setted( $cookie_setted ) {
    	// check some conditions, set to false forces output of css/js/html
    	$cookie_setted = false;
    	return $cookie_setted;
    }
    add_filter( 'cn_cookie_setted', 'my_cn_cookie_setted' );

    Please note that such a filter is NOT in official plugin (yet).

    Plugin Author dFactory

    (@dfactory)

    This kind of filter will be available in the next release of the plugin.
    It’s name will be “cn_is_cookie_setted”
    So if you adjust the code and use “cn_is_cookie_setted” filter hook name your code will work after the update as well.

    Alternatively we’re thinking of loading css/js always, possibly moving the generated cookie notice bar HTML content into JS.

    Honestly we did not have any issues with Autopzimize caching, but if yo do please stick to the filter hook solution for now.

    Regards,
    Bartosz Arendt / dfactory team

    Thanks for considerung the filter.

    About the issue, most users of Autoptimize also use a page cache plugin as recommended on Autoptimize plugin-page and that’s where the current Cookie-Notice behaviour breaks sites.

    Scenario:

    1. page cache of a website expires or is purged by admin or other triggers
    2. the very next visitor of the website has cookie_notice_accepted cookie set in his browser
    3. the html-page is rendered by WordPress, stored in page cache and sent to visitor
    4. the html-page does not have the Cookie-Notice js/css/html due to cookie_setted() check
    5. all following visitors get the stored html-page without js/css/html from cache
    6. Cookie-Notice works not as expected (it can’t, it isn’t in page)

    Same scenario with Autoptimize. Even if Autoptimize creates various versions of combined js/css per page with/without Cookie-Notice code, only one version will end up linked in html in page cache, result not as expected.

    Sidenote: For the very same reason this solution won’t work with common used default page cache configurations.

    The filter, now named cn_is_cookie_set, has been added in 1.2.38 and appears to work fine.

    Cache plugin users (Autoptimize, WP Super Cache, WP Fastest Cache etc.) should return false via this filter to solve above described problems.

    function my_cn_is_cookie_set( $cookie_set ) {
    	return false; // force output of css/js/html
    }
    add_filter( 'cn_is_cookie_set', 'my_cn_is_cookie_set' );

    Thanks for the great plugin.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Caching Problems with autoptimize’ is closed to new replies.