Title: Working with Autoptimize
Last modified: September 1, 2016

---

# Working with Autoptimize

 *  Resolved [ac1643](https://wordpress.org/support/users/ac1643/)
 * (@ac1643)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/)
 * Hi
 * Is there any way to make your plugin work alongside the Autoptimize plugin?
 * At the moment I would have to separately purge both caches. Could a connection
   be made so that when your plugin purges, so does Autoptimize cache (or vice-versa)
 * Thanks
 * [https://wordpress.org/plugins/varnish-http-purge/](https://wordpress.org/plugins/varnish-http-purge/)

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

 *  Plugin Contributor [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529827)
 * [https://wordpress.org/plugins/autoptimize/](https://wordpress.org/plugins/autoptimize/)?
 * I’d guess you’re having a race condition, where Autoptimize cache is caching 
   around the same time as Varnish.
 *  [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529836)
 * Hiya Mika;
    Seems the question is rather; does Varnish HTTP purge have a method
   AO could invoke to purge Varnish’ cache when AO’s is deleted (to avoid having
   HTML in Varnish which references autoptimized CSS/ JS which does not exist any
   more)?
 * frank
 *  [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529837)
 * Or, alternatively [as some page caching plugins do](http://blog.futtta.be/2016/02/20/hyper-cache-hooking-up-with-autoptimize/),
   could Varnish HTTP purge hook into an Autoptimize action (`autoptimize_action_cachepurged`)
   to delete it’s own page cache.
 * somehow I’d like that even better 😉
 * frank
 *  Plugin Contributor [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529849)
 * You can edit your posts for an hour from making it, to prevent a double post,
   Frank.
 * And I understood the question, I wanted to be sure I was looking at the right
   plugin 🙂 There are 45k plugins. I try not to assume the one I think they mean
   is the right one.
 * That’s a funny question, y’know… Because I’m not sure what the best order here
   is, in part because I’m not 100% up to speed on how your plugin (if that IS the
   right one 😉 ) works. Looking at how you coded around WP Super Cache, that may
   be the route we have to do.
 * I already have a filter for `varnish_http_purge_events`:
 *     ```
       protected function getRegisterEvents() {
   
       		// Define registered purge events
       		$actions = array(
       			'save_post',            // Save a post
       			'deleted_post',         // Delete a post
       			'trashed_post',         // Empty Trashed post
       			'edit_post',            // Edit a post - includes leaving comments
       			'delete_attachment',    // Delete an attachment - includes re-uploading
       			'switch_theme',         // Change theme
       		);
   
       		// send back the actions array, filtered
       		// @param array $actions the actions that trigger the purge event
       		return apply_filters( 'varnish_http_purge_events', $actions );
       	}
       ```
   
 * That would work for individual posts.
 * Though it sounds like you need to flush the WHOLE cache and not just the ones
   for the post? I’m not 100% sure ‘when’ this situation is popping up. I’m guessing
   that what’s going on is the OP is flushing the Autoptimize cache after making‘
   some change’ to the theme, and then has to flush the whole Varnish cache.
 * I don’t have a way to externally trigger the whole Varnish cache. It’s intentional
   that it has to be a conscious manual action, since you really should RARELY be
   doing anything that requires it. The common situations are ‘adding new plugins’
   and ‘changing themes manually’ which really should be rare occurrences.
 *  [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529877)
 * The use case indeed is purging the entire cache of both Autoptimize and Varnish,
   so a pity there’s no such action in Varnish HTTP Purge.
 * But wouldn’t `switch_theme` in your array of registered purge events have to 
   result in the flushing of the entire Varnish cache?
 * frank
 *  Plugin Contributor [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529926)
 * You don’t have to sign your posts 🙂 Frank you should read [https://codex.wordpress.org/Forum_Welcome](https://codex.wordpress.org/Forum_Welcome)
 * switch_theme IS in there for flushing cache already (I thought it was removed,
   but I see it in my 3.9 alpha code …)
 * That said, I know your usecase is purging both, but that’s not actually a full
   usecase. WHY do you need to flush the whole Autoptimize cache? What changes are
   being made? How often do people really do this? The OP made it sound like it 
   was a regular occurrence which a full cache flush really should never be.
 * Using any caching while actively developing your site’s design is a recipe for
   pain 🙂
 *  Plugin Contributor [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529932)
 * Hours later, I see why it’s not happening in certain cases. 3.9 will address 
   this and add in a filter so people can add events that trigger a full flush.
 *  [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529935)
 * > You don’t have to sign your posts 🙂
 * I’m stubbornly formal in a somewhat informal manner 😉
 * > WHY do you need to flush the whole Autoptimize cache? What changes are being
   > made? How often do people really do this? The OP made it sound like it was 
   > a regular occurrence which a full cache flush really should never be.
 * well, purging AO’s cache for one page only is not possible, as the same autoptimized
   file (CSS or JS) can very well (and ideally is) used accross multiple pages/ 
   posts/ archives/ … hence the a cache purge for AO is always a full one. typically
   users would do that when something changes in the CSS/ JS, be it when switching
   themes or installing (or removing) plugins.
 * > Using any caching while actively developing your site’s design is a recipe 
   > for pain 🙂
 * sure, but a WordPress install is always in flux with theme or plugin updates (
   or installs or removals).
 * > Hours later, I see why it’s not happening in certain cases. 3.9 will address
   > this and add in a filter so people can add events that trigger a full flush.
 * great!! 🙂
 * kind regards,
    frank
 *  Plugin Contributor [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529957)
 * > sure, but a WordPress install is always in flux with theme or plugin updates(
   > or installs or removals).
 * Okay that’s a hella good point. I stopped using Google PageSpeed because flushing
   the compressed CSS/JS was an exercise in swearing.
 * I’m tempted to put in an auto-flush when you activate/deactivate a plugin, except
   that’s not always when the need might occur… Hrm.
 * I can add in autoptimize_action_cachepurged though! No real harm in that.
 * If you want to test it with 3.9, you can download the zip here – [https://github.com/Ipstenu/varnish-http-purge/archive/REL_3.9.zip](https://github.com/Ipstenu/varnish-http-purge/archive/REL_3.9.zip)
 * I’ve tested it on a live site and it works as I think it should.
 *  [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529982)
 * Can’t test now (on holiday), but that should indeed work perfectly.
 * ac1643, can you test?
 * sunny greetings from the south of France 😉
    frank
 *  Thread Starter [ac1643](https://wordpress.org/support/users/ac1643/)
 * (@ac1643)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529997)
 * Hi Mika and Frank, thanks for collaborating on this. I am also away right now
   but should be able to test by the start of next week.
 * Many thanks

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

The topic ‘Working with Autoptimize’ is closed to new replies.

 * ![](https://ps.w.org/varnish-http-purge/assets/icon-256x256.png?rev=3027185)
 * [Proxy Cache Purge](https://wordpress.org/plugins/varnish-http-purge/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/varnish-http-purge/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/varnish-http-purge/)
 * [Active Topics](https://wordpress.org/support/plugin/varnish-http-purge/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/varnish-http-purge/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/varnish-http-purge/reviews/)

 * 11 replies
 * 3 participants
 * Last reply from: [ac1643](https://wordpress.org/support/users/ac1643/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/working-with-autoptimize/#post-7529997)
 * Status: resolved