Hi, I'm updating an Astro site to version 3.0, I wanted to ask if there is a way to download and optimize all the remote images with astro:assets like the image integration did before. I know I can use remotePatterns to get images from certain domains or subdomains, but the images I'm downloading are user generated content and are not limited to a list of hosts. Currently I'm using patterns **.com, **.org and a few more, but this would break as soon as someone inputs an image with a different tld.
#Download and compress all remote images
3 messages · Page 1 of 1 (latest)
Hi @plucky wolf. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Astro's built-in astro:assets feature allows you to optimize local images and configured remote images. However, it does not automatically download and optimize all remote images. You can configure lists of authorized image source URL domains and patterns for image optimization using image.domains and image.remotePatterns. This configuration is an extra layer of safety to protect your site when showing images from an external source [^1^].
For example, you can allow remote images from astro.build to be optimized like this:
export default defineConfig({ image: { domains: ["astro.build"], }});
Or allow remote images from HTTPS hosts like this:
export default defineConfig({ image: { remotePatterns: [{ protocol: "https" }], }});
However, as you mentioned, this approach has limitations when dealing with user-generated content that can come from any domain.
Unfortunately, based on the provided extracts, there doesn't seem to be a built-in way in Astro to automatically download and optimize all remote images regardless of their source. You might need to implement a custom solution for this, possibly involving a server-side script to download and optimize images, or using a third-party service that can handle image optimization from any source.