How to flush the CDN cache for Autoptimize

Note: If you want to flush the cache for a specific image (not all), please refer to this article.

If you want to flush the whole ShortPixel's CDN cache for a WordPress website using Autoptimize with the image optimization option turned on, here's how you can do it:

  1. Install a code snippet plugin like this one.
  2. Go to Snippets > Add New.
  3. Give the snippet a name and copy-paste the code snippet below.
  4. Choose "Only run on site front-end". This will replace the CDN URL from https://sp-ao.shortpixel.ai/client/ to https://sp-ao.shortpixel.ai/client2/ . The effect of this operation is to actually flush the whole cache.
add_filter('autoptimize_html_after_minify','change_shortpixel_client', 11, 1); 
function change_shortpixel_client( $HtmlIn ) {     
	return str_replace( 'sp-ao.shortpixel.ai/client/', 'sp-ao.shortpixel.ai/client2/', $HtmlIn ); 
}

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us