-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
passthroughImageService shouldn't output multiple files #9002
Copy link
Copy link
Closed
Labels
- P2: nice to haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)feat: assetsRelated to the Assets feature (scope)Related to the Assets feature (scope)
Description
Astro Info
Astro v3.4.3
Node v20.5.1
System macOS (arm64)
Package Manager npm
Output hybrid
Adapter @astrojs/cloudflare
Integrations @astrojs/mdx
@astrojs/tailwind
@astrojs/vue
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
- The noop image service only copies contents into the target file
- Some things enable it implicitly (e.g.
@astrojs/cloudflare) - When multiple dimensions are used for a single image (multiple
<Image>tags for the same image, with different dimensions), it produces multiple files even if they have the exact same contents (= same as original image) - This unnecessarily leads to multiple requests — different
<img>tags requesting different URLs, even if they all have the exact same content (untransformed content, same as source image)
Reproduction steps (don't have the time to set up a Stackblitz example right now):
- Add an image (
src/example-image.png) - Add this code to any page:
<Image src={importedImage} width="100" alt="foo" /> <Image src={importedImage} width="200" alt="bar" />
- Use
passthroughImageService()in your Astro config - Run a static build and notice
example-image.png,example-image.hash1.webp,example-image.hash2.webpin yourdist/_astro - Browser requests both
example-image.hash1.webpandexample-image.hash2.webpeven if they have the same contents
What's the expected result?
Only produce a single .webp file, or none at all and just use the original format.
Don't think this can be solved in packages/astro/src/assets/services/noop.ts since that only deals with the contents of the output file. The path to the output file is probably handled by the code that calls noopService.
Link to Minimal Reproducible Example
See the bug description
Participation
- I am willing to submit a pull request for this issue.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
- P2: nice to haveNot breaking anything but nice to have (priority)Not breaking anything but nice to have (priority)feat: assetsRelated to the Assets feature (scope)Related to the Assets feature (scope)