Title: Code: Integrating the Autoptimize plugin
Last modified: August 30, 2016

---

# Code: Integrating the Autoptimize plugin

 *  [Benjamin Pick](https://wordpress.org/support/users/benjaminpick/)
 * (@benjaminpick)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/code-integrating-the-autoptimize-plugin/)
 * When the button is clicked, autoptimize should clear as well.
 * Here is my code for all to copy:
 * [https://gist.github.com/benjaminpick/94b487ce995454797143](https://gist.github.com/benjaminpick/94b487ce995454797143)
 * [https://wordpress.org/plugins/clear-cache-for-widgets/](https://wordpress.org/plugins/clear-cache-for-widgets/)

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

 *  Thread Starter [Benjamin Pick](https://wordpress.org/support/users/benjaminpick/)
 * (@benjaminpick)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/code-integrating-the-autoptimize-plugin/#post-6314832)
 * Thank you, dear dev, for the plugin hooks! But if you like you’re free to integrate
   it in your plugin.
 *  Plugin Author [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * (@webheadllc)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/code-integrating-the-autoptimize-plugin/#post-6315190)
 * Sweeet! thank you. I’ll add this in soon. Sorry haven’t been checking the forums
   lately.
 *  Plugin Author [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * (@webheadllc)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/code-integrating-the-autoptimize-plugin/#post-6315193)
 * Hey Benjamin,
 * Could you give me an example when autoptimize’s cache should be cleared when 
   updating menus, widgets, or using the customizer? It seems like only the css 
   and js is cached and I can’t think of any time when those files are updated outside
   of development.
 *  Thread Starter [Benjamin Pick](https://wordpress.org/support/users/benjaminpick/)
 * (@benjaminpick)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/code-integrating-the-autoptimize-plugin/#post-6315194)
 * Good point. Well, CSS and JS may change when WordPress, a theme or a plugin is
   updated – not sure if you have covered this use case yet?
 * Actually there is a small problem of my current approach of deleting the optimized
   files as well. In very rare cases the Cache delivered an old HTML, and before
   the CSS/JS-Files are loaded the cache is purged, and autoptimize changes the 
   filenames if the content has changed, thus the HTML rendered with 404 for CSS/
   JS. Not good. So actually it would be better to defer the purging of the autoptimizer
   for some seconds via wp-cron.
 * Oh actually clearing the cache of this should not be essential, because the filename
   contains a hash that changes with the content, so new content -> new files. Maybe
   you just add my gist to your readme for the developer use case.
 *  Plugin Author [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * (@webheadllc)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/code-integrating-the-autoptimize-plugin/#post-6315196)
 * ok, it’s in the readme.

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

The topic ‘Code: Integrating the Autoptimize plugin’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/clear-cache-for-widgets.svg)
 * [Clear Cache for Me](https://wordpress.org/plugins/clear-cache-for-widgets/)
 * [Support Threads](https://wordpress.org/support/plugin/clear-cache-for-widgets/)
 * [Active Topics](https://wordpress.org/support/plugin/clear-cache-for-widgets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/clear-cache-for-widgets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/clear-cache-for-widgets/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/code-integrating-the-autoptimize-plugin/#post-6315196)
 * Status: not a support question