sst / open-next

Open source Next.js serverless adapter
https://open-next.js.org
MIT License
3.7k stars 111 forks source link

Feat add a static etag for Image #398

Closed conico974 closed 3 months ago

conico974 commented 3 months ago

At the moment, image from _next/image are only cached in the cdn. We don't generate any ETag either for the image so we never get 304. Every stale request actually needs to be recomputed again.

In order to improve perf and reduce cost, this PR introduces an env variable OPENNEXT_STATIC_ETAG that we can set on the image opt function. When you set this env variable, we create an ETag that depends on some parameter that we know before performing the image opt: ( href, width, quality, buildId ) Stale request will then return a 304 for request where if-none-match header is equal to the computed ETag

One important things to note, when using this env variable, it means that all the images should be considered immutable (The source image should not change) and the only way to change that is to change the BUILD_ID (on new deploy)

Not sure if this should be enabled by default or not.

changeset-bot[bot] commented 3 months ago

🦋 Changeset detected

Latest commit: d83c12e73cc271059639a7975e9e0dc358f6d07a

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

This PR includes changesets to release 4 packages | Name | Type | | ---------------- | ----- | | open-next | Patch | | app-pages-router | Patch | | app-router | Patch | | tests-unit | Patch |

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

vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
open-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2024 11:24am