astro:assets · public/ · Local

Optimize Astro Images — Feed the Image Component Lean Sources

Astro's Image component optimizes what it can see. Compress the rest, public/ files, CSS backgrounds and oversized originals, before you build.

Quick answer

Astro's <Image /> processes local images imported from src/ at build time, but files in public/ are copied untouched, and CSS backgrounds never go through it. Compress public/ with TinyPixels, and resize oversized source images so the component starts from something sensible.

How to compress images before an Astro build

1

Download and open TinyPixels

Free to install on Mac or Windows — no account needed to start.

2

Resize camera and design originals

Multi-thousand-pixel sources slow builds even though Astro will generate smaller variants.

3

Compress public/ and keep source quality high

Compress public/ files fully. For src/ images that <Image /> will re-encode, use light compression so you do not stack lossy passes.

4

Commit and build

Static output now ships smaller files from both paths.

Where Astro's image pipeline applies, and where it doesn't

Astro's astro:assets module gives you <Image />, <Picture /> and getImage(). When you pass them a local image imported from src/, Astro resizes it and converts it to a modern format at build time using its image service, which is Sharp by default. That is genuinely useful, and it is also the whole of the built-in optimization.

Everything outside that path is untouched: files in public/ are copied to the output as-is, CSS background images are not processed by the component, and plain <img> tags pointing at public/ get no help. Those are the files where compressing yourself has the biggest effect.

One subtlety: <Image /> re-encodes from your source. If the source has already been squeezed at a low quality setting, a second lossy pass can add visible artifacts. So for images headed into the component, resize them and compress lightly; for public/ images that ship directly, compress to your final target.

public/ finally optimized

These files bypass Astro entirely, so this is where a pass pays off most.

Sensible sources for <Image />

Trim huge originals so builds stay fast and variants start clean.

No integration to add

Works alongside astro:assets; no config changes required.

Format conversion

Convert public/ hero art to WebP or AVIF and update references.

What Astro's image tooling processes

SourceWhat happens at buildYour move
<Image /> or <Picture /> with a src/ importResized and converted to the chosen formats by the image service.Resize the source; compress lightly
Markdown images that reference local files in src/Processed like imported images.Same as above
Files in public/Copied to the output untouched.Compress fully before commit
CSS background-imageNot handled by the Image component.Compress the referenced file
Remote image URLsOnly processed if the domain is authorized in your config.Not affected by a local pass

Astro's image options evolve between versions, so check the current astro:assets docs for supported formats and settings.

Common mistakes with Astro images

Putting images in public/ and expecting <Image /> to optimize them

The component works on imported files. Anything in public/ is skipped, so move it to src/ if you want processing, or compress it by hand.

Feeding 6000 px camera files to the component

Astro will make smaller variants, but processing huge sources makes builds slower. Resize them first.

Over-compressing sources that will be re-encoded

Two lossy passes compound. Keep quality high on images going into <Image />.

Forgetting social-card and CSS images

Open Graph images and CSS backgrounds usually live outside the component, so nothing optimizes them unless you do.

Frequently asked questions

Does Astro optimize images automatically?

Partly. <Image /> and <Picture /> optimize local images imported from src/ at build time. Files in public/ and CSS backgrounds are not processed.

Should images go in public/ or src/ in Astro?

Use src/ for images you want processed by astro:assets, and public/ for files that need a fixed URL. Compress public/ files yourself, since they ship untouched.

Should I compress images before using the Astro Image component?

Resize large originals and use light compression. The component re-encodes from the source, so avoid stacking aggressive lossy passes.

Does Astro support AVIF?

Yes, you can choose AVIF as an output format for the Image component and Picture. Check the current docs for the options available in your version.

Can I batch compress my whole Astro project at once?

Yes. Drop public/ or your assets folder into TinyPixels and every image compresses in one local pass.

Build a leaner Astro site

Free to start. No credit card, no account, no cloud. See Pro pricing →