To maximize website performance in a WordPress site we should serve images and other static assets via a content delivery network (CDN). Jetpack plugin, the ultimate toolkit for WordPress offers just that for free. Using its image CDN (formerly Jetpack Photon) you could host all your images freely on the blazing-fast WordPress infrastructure. Thus easing load on your server and serving images faster to your site visitors.
JetPack Image CDN by default does not rewrite images uploaded with Advanced Custom Fields. But you could use the Photon API to transform images using GET query arguments.
Add Jetpack Photon CDN filter to your ACF image field (make sure you have the ACF image field set to return images are URL).
<?php echo apply_filters( 'jetpack_photon_url', get_field('image_field') ); ?>
If you' have already built out a WordPress theme with ACF image fields and it's hard to change each one of them (in numerous theme files) with the above snippet, then you could try the below snippet (add it to your theme functions.php file).
function acf_image_photon_urls($url, $post_id) {
return str_replace('yourdomian.com/wp-content/uploads', 'i0.wp.com/yourdomian.com/wp-content/uploads', $url);
}
add_filter('acf/format_value/type=image', 'acf_image_photon_urls', 2);
The above snippet replaces all images in the ACF image field type to Jetpack image CDN URL based URLs. You could also replace the i0.wp.com Jetpack Photon CDN URL in the above code to any of these - i1.wp.com, i2.wp.com or i3.wp.com CDN domains.