🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Performance••By Komal Nakrani

Astro Image CDN Options: When and How to Use One

Astro image CDN options compared: host image services on Vercel, Netlify and Cloudflare, plus Cloudinary, imgix, ImageKit and Unpic, with config and code.

#Astro#Images#Image CDN#Performance#Cloudinary

An Astro image CDN resizes and converts images on request at the edge instead of at build time. Use one when your site has many images, images that come from a CMS, or builds that are slow because of image processing. The easiest options are your host’s own image service (Vercel, Netlify, Cloudflare) through the Astro adapter; dedicated services like Cloudinary, imgix and ImageKit add transformations, a media library and multi-host portability.

For small and medium static sites, Astro’s default Sharp service is often all you need: it optimises local images once during astro build and serves them as static files. An image CDN becomes worth it when that build step gets slow or your images do not live in the repository.

Key Takeaways

  • Astro’s default <Image /> optimises images at build time with Sharp. No CDN is required.
  • Host image services (Vercel, Netlify, Cloudflare) plug into astro:assets through the adapter, so your <Image /> code does not change.
  • Cloudinary, imgix and ImageKit offer richer transforms and work on any host, usually through their own components or URL builders.
  • Remote images need image.remotePatterns or image.domains for Astro to optimise them.
  • Measure before switching: build time, image weight and LCP tell you if a CDN is paying off.

How Astro handles images by default

Astro’s astro:assets module provides <Image /> and <Picture />. For local images, imports give Astro the dimensions, and the build writes resized, converted files to dist/_astro/:

---
// src/components/Hero.astro
import { Image } from 'astro:assets';
import hero from '../assets/hero.jpg';
---
<Image src={hero} alt="Team at work in the studio" width={1200} layout="constrained" priority />

With layout="constrained", Astro generates srcset and sizes for responsive loading. priority disables lazy loading and raises fetch priority for the LCP image. The responsive images tip and the Image vs Picture vs img guide cover the options.

This approach has two costs. Every image variant is generated during the build, which grows with image count, and images from a CMS must be downloaded and processed at build time too. An image CDN moves that work to request time and caches the result.

When an image CDN makes sense

Situation Default Sharp Image CDN
Under a few hundred local images Good Not needed
Thousands of images, slow builds Builds grow long Better
Images uploaded by editors in a CMS Works, but processed every build Better
On-demand (SSR) pages with images Uses the /_image endpoint on your server Better
Need crops, face detection, overlays Limited Better
Want zero external services Better Adds a vendor

1. Vercel Image Optimization

With @astrojs/vercel, set imageService: true and astro:assets uses Vercel’s image optimisation in production. Your components stay the same.

// astro.config.mjs
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel';

export default defineConfig({
  adapter: vercel({ imageService: true }),
  image: {
    remotePatterns: [{ protocol: 'https', hostname: 'images.example-cms.com' }],
  },
});

In development, Astro still uses Sharp locally. Check Vercel’s pricing for image transformation limits on your plan.

Good for: sites already deployed on Vercel.

2. Netlify Image CDN

The @astrojs/netlify adapter routes astro:assets through Netlify Image CDN by default (the imageCDN option). Images are transformed on request and cached at the edge.

// astro.config.mjs
import { defineConfig } from 'astro/config';
import netlify from '@astrojs/netlify';

export default defineConfig({
  adapter: netlify(),
  image: {
    domains: ['images.example-cms.com'],
  },
});

Set imageCDN: false if you prefer build-time optimisation. Remote domains must be allowed in Astro’s config, which the adapter passes to Netlify.

Good for: Netlify deploys with CMS images.

3. Cloudflare Images

The @astrojs/cloudflare adapter has an imageService option. Set it to 'cloudflare' to use Cloudflare’s image resizing, which requires the feature enabled on your zone. Other values keep build-time processing or pass images through untouched.

// astro.config.mjs
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
  adapter: cloudflare({ imageService: 'cloudflare' }),
});

Check the adapter’s README for the current list of imageService values, because they have changed between adapter versions.

Good for: sites on Cloudflare that want edge transforms with no extra vendor.

4. Cloudinary

Cloudinary is a full media platform: upload, storage, a media library for editors, and URL-based transformations (crops, gravity, overlays, format and quality selection). The astro-cloudinary package provides components:

npm install astro-cloudinary
---
// src/components/ProductPhoto.astro
import { CldImage } from 'astro-cloudinary';
---
<CldImage src="products/blue-chair" width="800" height="600" crop="fill" gravity="auto" alt="Blue lounge chair" />

Set PUBLIC_CLOUDINARY_CLOUD_NAME in your environment. Cloudinary also offers a content loader for bringing assets into content collections.

Good for: media-heavy sites, e-commerce, and teams who want a media library.

5. imgix

imgix transforms images stored in your own bucket (S3, Google Cloud Storage, Azure) or web folder, using URL parameters. You can build URLs yourself and pass them to a plain <img> with a srcset:

---
// src/components/Photo.astro
interface Props { path: string; alt: string }
const { path, alt } = Astro.props;
const base = `https://example.imgix.net/${path}`;
const widths = [400, 800, 1200, 1600];
const srcset = widths.map((w) => `${base}?w=${w}&auto=format,compress ${w}w`).join(', ');
---
<img src={`${base}?w=800&auto=format,compress`} srcset={srcset} sizes="(max-width: 800px) 100vw, 800px" alt={alt} loading="lazy" decoding="async" />

auto=format serves AVIF or WebP when the browser supports it.

Good for: teams that keep originals in their own storage and want a pure transformation layer.

6. ImageKit, Bunny and other URL-based CDNs

ImageKit, Bunny Optimizer and similar services follow the same model as imgix: point them at an origin, then request images with width and format in the URL. The component above works with small URL changes. They are often cheaper at modest volume; compare current pricing for your traffic.

7. Unpic for any CDN

@unpic/astro provides an Image component that detects the CDN from the URL (Cloudinary, imgix, ImageKit, Shopify, Contentful, Sanity, Storyblok and many more) and generates the right srcset using that CDN’s own parameters:

---
// src/components/CmsImage.astro
import { Image } from '@unpic/astro';
const { src, alt } = Astro.props;
---
<Image src={src} alt={alt} layout="constrained" width={800} height={533} />

There is no Astro-side processing; the CDN does the work. This is a good fit for headless CMS images, since most CMSs already serve images through a CDN.

Good for: sites pulling images from a headless CMS or Shopify.

8. A custom image service

Astro lets you plug in your own service through image.service. An external service only needs to return a URL for the requested transform, which makes it straightforward to wrap any URL-based CDN so <Image /> and <Picture /> keep working:

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  image: {
    service: { entrypoint: './src/image-service.ts' },
  },
});

Your entrypoint exports getURL() (and optionally validateOptions() and getSrcSet()). The image service reference documents the interface. If you want no processing at all, passthroughImageService() from astro/config leaves images untouched.

Comparison table

Option Works on any host Setup in Astro Editor media library Advanced transforms
Sharp (default) Yes None No Basic
Vercel Vercel only Adapter option No Basic
Netlify Image CDN Netlify only Adapter default No Basic
Cloudflare Images Cloudflare only Adapter option Optional Moderate
Cloudinary Yes Package + env var Yes Extensive
imgix Yes URL builder No Extensive
ImageKit / Bunny Yes URL builder Partial Moderate
Unpic Yes (uses your CMS CDN) Package Depends on CMS Depends on CDN

Allowing remote images

Whichever route you take, remote images optimised through astro:assets must be allowed in config, or Astro will refuse to process them:

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  image: {
    remotePatterns: [{ protocol: 'https', hostname: '**.example-cms.com' }],
  },
});

Remote images also need width and height (or inferSize) because Astro cannot read their dimensions from an import. See the remote image fix if you hit that error, and the Astro image cheatsheet for every prop.

How to decide

  1. Static site, images in the repo, builds under a few minutes: keep the default Sharp service.
  2. Builds slowed by images: switch to your host’s image service first, since it requires one config line.
  3. Images come from a CMS: use the CMS’s own CDN through Unpic or the CMS’s URL parameters.
  4. Media-heavy site or multiple hosts: Cloudinary or imgix.
  5. On-demand pages: use any CDN, so your server does not resize images per request.

After switching, compare total image bytes and LCP before and after with PageSpeed Insights. The Astro performance guide lists other checks. Every Komal Astro theme already uses astro:assets for its images, so any of the adapter-based options above work without code changes.

FAQ

Does Astro need an image CDN?

No. Astro’s default Sharp service optimises local images at build time and produces responsive, modern-format files. A CDN helps with large image libraries, CMS images and on-demand pages.

What is the best image CDN for Astro?

Start with your host’s image service, because it plugs into astro:assets with one adapter option. Choose Cloudinary or imgix if you need advanced transforms or want the same setup across hosts.

Can I use Cloudinary with the Astro Image component?

Cloudinary provides its own CldImage component through astro-cloudinary. You can also allow Cloudinary’s domain in image.remotePatterns and pass Cloudinary URLs to Astro’s <Image />, though then Astro processes them rather than Cloudinary.

Why are my Astro builds slow with many images?

Each image variant is generated during the build. Use an image CDN, reduce the number of widths, or enable your CI cache so the node_modules/.astro image cache persists between builds. The CI build cache tip shows how.

Do image CDNs work on static Astro sites?

Yes. URL-based CDNs like imgix, Cloudinary and Unpic work in fully static sites because the image URLs are just links. Host services on Vercel and Netlify also work with static output through the adapter.