sst / open-next

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

fix(open-next): correctly set cache control for html pages #353

Closed jadenv closed 5 months ago

jadenv commented 5 months ago

As the code reads in the comment right above the line I changed, NextServer will not respond with a cache-control header value for HTML pages.

Since the cache-control header value is never set upstream, open-next also never set its own cache-control header due to this truthy if check.

As HTML pages never got any cache-control value set, what should be some of the fastest pre-rendered pages actually become slower than SSR/ISR pages that do get a cache header set correctly. (In the case of cdk-nextjs, the value actually gets falls back to no-cache)

I tested this locally with a number of CloudFront events against a site with static HTML as well as other SSG/ISR page types and it helped a lot for static HTML pages. 🚀

changeset-bot[bot] commented 5 months ago

🦋 Changeset detected

Latest commit: ea2d0f46a166648a37675298496bff69032b19ae

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 5 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 Feb 1, 2024 10:45pm