Is it just me or does stale-while-revalidate not work on chrome at all?
I am so stumped. The browser will never serve the stale version after the max-age has expired. Any ideas?
I put a video over on twitter detailing the issue. I'd upload it here if I could
https://twitter.com/wesbos/status/1892679127259308145
I am so stumped. The browser will never serve the stale version after the max-age has expired. Any ideas?
I put a video over on twitter detailing the issue. I'd upload it here if I could
https://twitter.com/wesbos/status/1892679127259308145
Comments
export async function GET() {
await new Promise((r) => {
setTimeout(r, 5000)
})
return new NextResponse(new Date().toISOString(), {
headers: {
'cache-control': 'max-age=10, stale-while-revalidate=30',
'content-type': 'text-plain',
},
})
}
fetch('/api/timestamp')
// fetch while stale:
setTimeout(() => {
for (let i = 0; i < 5; ++i) {
fetch('/api/timestamp').then((res) => res.text()).then((text) => { console.log('done', i, new Date(), text) });
console.log('called fetch', i, new Date())
}
}, 17_000);
Five invocations at stale result in 10 network waterfall entries. Five are "fetch" and "disk cache". The sixth is text/plain, 291B. The remainder are text/plain, 0B. All the "fetch" responses have the same random number.