-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Astro Info
Astro v5.16.3
Vite v6.4.1
Node v25.2.0
System Linux (x64)
Package Manager pnpm
Output static
Adapter none
Integrations @astrojs/mdx (v4.3.12)
astro-compressor (v1.2.0)
@astrojs/sitemap (v3.6.0)
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I use Strapi to manage media files for my website. I recently added an Etag header, expecting that Astro would honor it as per #12426. However, it never re-uses images from its cache and keeps processing them on every build.
I found out that the problem is likely an internal caching mechanism in fetch here:
astro/packages/astro/src/assets/build/remote.ts
Lines 49 to 50 in 33333e8
| const req = new Request(src, { headers }); | |
| const res = await fetch(req); |
I assume it checks the Etag header internally and simply replays the original 200 response from the cache. Astro won't detect this as a cached response since it checks if the body is empty, which isn't the case here.
| if (revalidatedData.data.length) { |
Adding cache: "no-cache" to the Request options got it working, so that might be one possible solution.
What's the expected result?
Image processing should be skipped for images sent with an Etag header if its value hasn't changed. This should be indicated with the (revalidated cache entry) info when building.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-vddoqki9-dwswdbrh
Participation
- I am willing to submit a pull request for this issue.