View Categories

Can I use a different CDN with ShortPixel?

Read this first #

If all you want to do is a custom subdomain to deliver the images, and you don’t care about what CDN is used, we recommend you using the default ShortPixel’s CDN and follow this tutorial instead.
For increased security, if you want to specify which domains can serve images from your CDN, you should follow this tutorial instead.

If you have enabled WebP and/or AVIF in the plugin settings, there may be issues serving the correct format for browsers. This is because your CDN must support the Vary header (which, for example, is not available on Cloudflare’s free plan) and be configured to deliver the original format, the WebP version, and/or the AVIF version from the same URL, depending on the browser’s capabilities. This ensures the CDN knows (and caches and delivers accordingly) that there are two or three different files for the same URL, based on the Accept header sent by the browser.

Therefore, if you are not able to set up the Vary header, you have two options:

  1. Either disable both formats, WebP and/or AVIF,
  2. or simply use ShortPixel’s default CDN, which is among the fastest in the market.

Steps #

If you want to use your own CDN when using ShortPixel Adaptive Images (SPAI) or ShortPixel Image Optimizer (SPIO), instead of ShortPixel’s CDN, follow these steps:

  1. Think of a suitable subdomain name for the delivery of your images, such as cdn, img, images, media, and so on. For example, if your website is example.com and you choose img subdomain, your images will be served from img.example.com.
  2. Edit your DNS records to add a CNAME from cdn.example.com to no-cdn.shortpixel.ai. This step might be slightly different depending on what CDN you use. Remember that example.com  should be changed to your actual domain, and that cdn should be changed to something else if it’s already used by another CNAME, like images.example.com or media.example.com
  3. Make sure the new record (cdn.example.com) works as expected with an online tool like whatsmydns.net.
  4. Change the CDN domain / API URL on the WordPress settings.
    • If you are using SPAI, navigate to your WordPress dashboard and go to Settings > ShortPixel AI > Behavior > API URL. There, change the default URL to https://img.example.com/spai where img.example.com is the subdomain that you’ve set up above.
    • If you are using SPIO, navigate to your WordPress dashboard and go to Settings > ShortPixel > WebP/AVIF & CDN and enable the “Deliver the next generation images using the ShortPixel CDN” option. There, change the default URL to https://img.example.com/spio where img.example.com is the subdomain that you’ve set up above.
Please make sure you flush your website’s cache (whichever is applicable – caching plugin, server cache, CDN cache, and browser cache).

Examples #

Here you will find instructions on how to do the previous steps for the most important CDN providers.