Skip to content

Commit

Permalink
Set cache-control to no-cache for adaptive content
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Dec 20, 2024
1 parent fc7b16f commit 0a4c3a9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/gitbook/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(',');
Expand Down

0 comments on commit 0a4c3a9

Please sign in to comment.