From 0a4c3a98eab38d26d3255d3309d73a282cbcaa64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Fri, 20 Dec 2024 23:22:22 +0100 Subject: [PATCH] Set cache-control to no-cache for adaptive content --- packages/gitbook/src/middleware.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/gitbook/src/middleware.ts b/packages/gitbook/src/middleware.ts index 886c60d009..6f0389bfea 100644 --- a/packages/gitbook/src/middleware.ts +++ b/packages/gitbook/src/middleware.ts @@ -290,17 +290,17 @@ export async function middleware(request: NextRequest) { setMiddlewareHeader(response, 'referrer-policy', 'no-referrer-when-downgrade'); setMiddlewareHeader(response, 'x-content-type-options', 'nosniff'); - if (typeof resolved.cacheMaxAge === 'number') { - const cacheControl = `public, max-age=0, s-maxage=${resolved.cacheMaxAge}, stale-if-error=0`; - - if (process.env.GITBOOK_OUTPUT_CACHE === 'true' && process.env.NODE_ENV !== 'development') { - setMiddlewareHeader(response, 'cache-control', cacheControl); - setMiddlewareHeader(response, 'Cloudflare-CDN-Cache-Control', cacheControl); - } else { - setMiddlewareHeader(response, 'x-gitbook-cache-control', cacheControl); - } + const cacheControl = + typeof resolved.cacheMaxAge === 'number' + ? `public, max-age=0, s-maxage=${resolved.cacheMaxAge}, stale-if-error=0` + : 'no-cache'; + + if (process.env.GITBOOK_OUTPUT_CACHE === 'true' && process.env.NODE_ENV !== 'development') { + setMiddlewareHeader(response, 'cache-control', cacheControl); + setMiddlewareHeader(response, 'Cloudflare-CDN-Cache-Control', cacheControl); + } else { + setMiddlewareHeader(response, 'x-gitbook-cache-control', cacheControl); } - // } if (resolved.cacheTags && resolved.cacheTags.length > 0) { const headerCacheTag = resolved.cacheTags.join(',');