diff --git a/src/run/headers.test.ts b/src/run/headers.test.ts index c72d7b7f54..6e09f8958a 100644 --- a/src/run/headers.test.ts +++ b/src/run/headers.test.ts @@ -238,7 +238,7 @@ describe('headers', () => { expect(headers.set).toHaveBeenNthCalledWith( 1, 'netlify-cdn-cache-control', - 'public, max-age=0, must-revalidate', + 'public, max-age=0, must-revalidate, durable', ) }) @@ -257,7 +257,7 @@ describe('headers', () => { expect(headers.set).toHaveBeenNthCalledWith( 1, 'netlify-cdn-cache-control', - 'public, max-age=0, must-revalidate', + 'public, max-age=0, must-revalidate, durable', ) }) diff --git a/src/run/headers.ts b/src/run/headers.ts index d12f583cea..411edf0052 100644 --- a/src/run/headers.ts +++ b/src/run/headers.ts @@ -224,7 +224,7 @@ export const setCacheControlHeaders = ( const cdnCacheControl = // if we are serving already stale response, instruct edge to not attempt to cache that response headers.get('x-nextjs-cache') === 'STALE' - ? 'public, max-age=0, must-revalidate' + ? 'public, max-age=0, must-revalidate, durable' : `s-maxage=${requestContext.routeHandlerRevalidate === false ? 31536000 : requestContext.routeHandlerRevalidate}, stale-while-revalidate=31536000, durable` headers.set('netlify-cdn-cache-control', cdnCacheControl) @@ -246,7 +246,7 @@ export const setCacheControlHeaders = ( const cdnCacheControl = // if we are serving already stale response, instruct edge to not attempt to cache that response headers.get('x-nextjs-cache') === 'STALE' - ? 'public, max-age=0, must-revalidate' + ? 'public, max-age=0, must-revalidate, durable' : [ ...getHeaderValueArray(cacheControl).map((value) => value === 'stale-while-revalidate' ? 'stale-while-revalidate=31536000' : value, diff --git a/tests/integration/cache-handler.test.ts b/tests/integration/cache-handler.test.ts index 6d37909b2a..bb0b762205 100644 --- a/tests/integration/cache-handler.test.ts +++ b/tests/integration/cache-handler.test.ts @@ -65,7 +65,7 @@ describe('page router', () => { expect(call1.headers, 'a stale page served with swr').toEqual( expect.objectContaining({ 'cache-status': '"Next.js"; hit; fwd=stale', - 'netlify-cdn-cache-control': 'public, max-age=0, must-revalidate', + 'netlify-cdn-cache-control': 'public, max-age=0, must-revalidate, durable', }), ) @@ -223,7 +223,7 @@ describe('app router', () => { // It will be stale instead of hit expect.objectContaining({ 'cache-status': '"Next.js"; hit; fwd=stale', - 'netlify-cdn-cache-control': 'public, max-age=0, must-revalidate', + 'netlify-cdn-cache-control': 'public, max-age=0, must-revalidate, durable', }), ) expect( diff --git a/tests/integration/fetch-handler.test.ts b/tests/integration/fetch-handler.test.ts index 8d8905968a..398f8355fe 100644 --- a/tests/integration/fetch-handler.test.ts +++ b/tests/integration/fetch-handler.test.ts @@ -195,7 +195,7 @@ test('if the fetch call is cached correctly (cached page res expect(post1.headers, 'a stale page served with swr').toEqual( expect.objectContaining({ 'cache-status': '"Next.js"; hit; fwd=stale', - 'netlify-cdn-cache-control': 'public, max-age=0, must-revalidate', + 'netlify-cdn-cache-control': 'public, max-age=0, must-revalidate, durable', }), ) @@ -264,7 +264,7 @@ test('if the fetch call is cached correctly (cached page res expect(post3.headers, 'a stale page served with swr').toEqual( expect.objectContaining({ 'cache-status': '"Next.js"; hit; fwd=stale', - 'netlify-cdn-cache-control': 'public, max-age=0, must-revalidate', + 'netlify-cdn-cache-control': 'public, max-age=0, must-revalidate, durable', }), ) diff --git a/tests/integration/simple-app.test.ts b/tests/integration/simple-app.test.ts index 8d5dfcfdb8..3b17f7130c 100644 --- a/tests/integration/simple-app.test.ts +++ b/tests/integration/simple-app.test.ts @@ -198,7 +198,7 @@ test('cacheable route handler is cached on cdn (revalidate=1 const firstTimeCachedResponse = await invokeFunction(ctx, { url: '/api/cached-revalidate' }) // this will be "stale" response from build expect(firstTimeCachedResponse.headers['netlify-cdn-cache-control']).toBe( - 'public, max-age=0, must-revalidate', + 'public, max-age=0, must-revalidate, durable', ) // allow server to regenerate fresh response in background