How to flush CDN cache for Autoptimize

If you need to flush the whole CDN cache for a 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. Add the code snippet below and, if you are given the option, choose to run it only on the site front-end.

    add_filter('autoptimize_html_after_minify','change_shortpixel_client', 11, 1);
    function change_shortpixel_client( $HtmlIn ) {
         return str_replace( 'cdn.shortpixel.ai/client/', 'cdn.shortpixel.ai/client2/', $HtmlIn );
    }

This will replace the CDN URL from https://cdn.shortpixel.ai/client/ to https://cdn.shortpixel.ai/client2/ and the effect of this is to actually flush the whole cache.

Still need help? Contact Us Contact Us