Title: Caching Problems with autoptimize
Last modified: September 14, 2016

---

# Caching Problems with autoptimize

 *  [Harry Milatz](https://wordpress.org/support/users/harry-milatz/)
 * (@harry-milatz)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/caching-problems-with-autoptimize/)
 * Hi,
    i am useing the plugin autoptimize [https://wordpress.org/plugins/autoptimize/](https://wordpress.org/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)

 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/caching-problems-with-autoptimize/#post-8603929)
 * Same problem here, would suggest an option “load always js/css” for better compatibility
   with caching and/or minimizing plugins.
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/caching-problems-with-autoptimize/#post-8637305)
 * Any plans to fix this in near future? Don’t want to “hack” plugin-files after
   each update. 🙁
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/caching-problems-with-autoptimize/#post-8640356)
 * 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](https://wordpress.org/support/users/dfactory/)
 * (@dfactory)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/caching-problems-with-autoptimize/#post-8641131)
 * 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
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/caching-problems-with-autoptimize/#post-8643920)
 * Thanks for considerung the filter.
 * About the issue, most users of Autoptimize also use a page cache plugin as recommended
   on [Autoptimize plugin-page](https://wordpress.org/plugins/autoptimize/) 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](https://wordpress.org/support/topic/disable-for-mobile-6/#post-7717601)
   with common used default page cache configurations.
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/caching-problems-with-autoptimize/#post-8735312)
 * 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.

 * ![](https://ps.w.org/cookie-notice/assets/icon-256x256.png?rev=3549327)
 * [Compliance by Hu-manity.co](https://wordpress.org/plugins/cookie-notice/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cookie-notice/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cookie-notice/)
 * [Active Topics](https://wordpress.org/support/plugin/cookie-notice/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cookie-notice/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cookie-notice/reviews/)

## Tags

 * [cache](https://wordpress.org/support/topic-tag/cache/)
 * [workaround](https://wordpress.org/support/topic-tag/workaround/)

 * 6 replies
 * 3 participants
 * Last reply from: [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/caching-problems-with-autoptimize/#post-8735312)
 * Status: not resolved