withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.93k stars 2.49k forks source link

Ensure final asset directory exists before writing cached files #12418

Closed oliverlynch closed 1 week ago

oliverlynch commented 1 week ago

Changes

Create the asset output folder before writing from cache.

If the first optimised image asset is cached astro re-optimises it as the cached file could not be written to the output directory, which is created after the cache step. Instead create the output directory first to prevent the unnecessary redownload and reprocessing of the first image asset.

Testing

Tested with the astro base template with a single remote image with 3 densities added, and successfully ran pnpm --filter astro run test. Improved test site optimised image generation time on rebuilds from ~280ms to ~1ms, although this is an extreme case.

Docs

N/A: Minor fix in caching behaviour that should conform to existing user expectations

changeset-bot[bot] commented 1 week ago

🦋 Changeset detected

Latest commit: fc486fadc3a2ee33fecf94a4bd438ade9aa73497

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR