Title: Clear autoptimize cache when plugins/core updated
Last modified: March 27, 2025

---

# Clear autoptimize cache when plugins/core updated

 *  Resolved [davedecc](https://wordpress.org/support/users/davedecc/)
 * (@davedecc)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/clear-autoptimize-cache-when-plugins-core-updated/)
 * Hello–
 * I find myself having to manually clear autoptimize cache of javascript files 
   especially after a plugin/core/etc update (typically things are broken and then
   I have to figure out what the cause was).
 * Is autoptimize not set by default to clear cache automatically on system updates?
   If not, can this be enabled to clear the cache on any updates like this to the
   underlying software?
 * Appreciate any insight you have.
 * Thanks!

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

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/clear-autoptimize-cache-when-plugins-core-updated/#post-18386958)
 * Theoretically (and in my experience also in reality) Autoptimize’s cache does
   not need to be cleared with core/ plugin updates, because when minifiying AO 
   compares (a hash) of the unminified source with the hashes in available the cache
   folder (e.g. autoptimize_single_xyz123.js for the previous version of whatever.
   js). if the contents of whatever.js changes, then the hash is different and this
   cache miss results in whatever.js being re-minified and cached with a different
   hash (autoptimize_single_abc456.js) 🙂
 * hope this clarifies,
    frank
 *  Thread Starter [davedecc](https://wordpress.org/support/users/davedecc/)
 * (@davedecc)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/clear-autoptimize-cache-when-plugins-core-updated/#post-18388869)
 * Thanks for the quick reply and insight! I hear you that this is typically the
   way it works.
 * In our case/environment (nginx page cache, redis object cache, cloudflare), almost
   all issues with updates are resolved once we clear the autoptimize cache, particularly
   with Gravity Forms. This is after we have already cleared all other caches, which
   does not resolve the issues but then the autoptimize clearing – which does not
   seem to fire automatically after those cache clears either – tends to fix everything.
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/clear-autoptimize-cache-when-plugins-core-updated/#post-18389301)
 * strange; when the page caches (nginx/ cloudflare) are cleared the page will be
   re-created by WordPress which will trigger Autoptimize which _should_ see new(
   uncached) JS and recreate it. is this something you can reproduce on a staging
   environment so I can check out the HTML (and links to JS-files) there? Or can
   you perform an webpagetest.org test at the moment the site is broken, that could
   also gave some idea of what is happening?
 * autoptimize does have logic, however, to clear it’s own cache if a “known” page
   cache is cleared, see [https://github.com/futtta/autoptimize/blob/beta/classes/autoptimizeMain.php#L280-L303](https://github.com/futtta/autoptimize/blob/beta/classes/autoptimizeMain.php#L280-L303)
 * suppose you have `nginx_cache_cleared` action, you could use the `autoptimize_filter_main_pagecachepurgeactions`
   filter to also listen for that action like this (warning: untested code);
 *     ```
       add_filter( 'autoptimize_filter_main_pagecachepurgeactions', 
         function( $clearcaches_array ) {
           $clearcaches_array[] = 'nginx_cache_cleared';
           return $clearcaches_array;
         },
         10,
         1
       );
       ```
   
 *  Thread Starter [davedecc](https://wordpress.org/support/users/davedecc/)
 * (@davedecc)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/clear-autoptimize-cache-when-plugins-core-updated/#post-18392705)
 * Thanks Frank, I’ll try to do a deeper dive on this the next time we run some 
   upgrades, I appreciate the snippet as well. Much appreciated!

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

The topic ‘Clear autoptimize cache when plugins/core updated’ is closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [davedecc](https://wordpress.org/support/users/davedecc/)
 * Last activity: [1 year, 2 months ago](https://wordpress.org/support/topic/clear-autoptimize-cache-when-plugins-core-updated/#post-18392705)
 * Status: resolved