zooniverse / front-end-monorepo

A rebuild of the front-end for zooniverse.org
https://www.zooniverse.org
Apache License 2.0
104 stars 29 forks source link

Next.js apps send invalid Cache-Control headers #6492

Open eatyourgreens opened 4 days ago

eatyourgreens commented 4 days ago

Package

Describe the bug

Neither of the Next.js apps set a duration for stale-while-revalidate. This means that Incremental Static Regeneration (ISR) won’t work as expected.

Response headers for the Zooniverse homepage on an iPhone.

To Reproduce

Go to https://www.zooniverse.org, or any project page served by Next.js, and inspect the response headers.

Expected behavior

stale-while-revalidate must specify a duration in seconds. See the MDN page for Cache-Control.


Cache-Control: max-age=604800, stale-while-revalidate=86400

Additional context

This is a very old bug in Next.js, fixed in https://github.com/vercel/next.js/pull/61330

Vercel deployments work without the duration, but that's a non-standard feature specific to Vercel. CDNs like CloudFront support the standard. I don't know what support is like in Azure FrontDoor.

eatyourgreens commented 4 days ago

I think Zooniverse is running quite an old version of Next.js, so probably needs to manually set swrDelta in the Next.js config. There have been a few bug fix releases since 14.2.7, including changes to how the duration is set for ISR revalidation.

I also think recent versions of Next.js set the revalidation time to one year by default.

More recently, the config key was renamed to expireTime.

eatyourgreens commented 4 days ago

This is from 2022, so might be outdated now, but says that Azure Front Door doesn't support stale-while-revalidate.

However, the related feature request is marked as completed.

Nginx might be the answer, in order to use ISR while self-hosting with AFD.

We'd also really like to see this in Front Door. Currently, we deploy an additional NGINX into our app service via Docker Compose to facilitate stale-while-revalidate for server-side rendered pages of our Next.js application.

goplayoutside3 commented 3 days ago

Agreed. This will be addressed when upgrading Next 14 --> Next 15.