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 and activate a code snippet plugin such as this one.
  2. Navigate to Snippets > Add New.
  3. Give the snippet a name and copy-paste the code snippet below.
  4. Below the code, choose "Only run on site front-end". This will replace all the instances of the CDN URL from sp-ao.shortpixel.ai/client/ to sp-ao.shortpixel.ai/client2/ . The effect of this operation is to actually flush the CDN 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