docs(cache): set Vercel edge Cache-Control for HTML pages (RFC#562 step 1) #56
Reference in New Issue
Block a user
Delete Branch "docs/rfc562-cache-headers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes the HTML cache-header gap on
docs.moleculesai.appcalled out in internal#562 audit. Currently HTML pages returnCache-Control: max-age=0, must-revalidateeven thoughx-vercel-cache: HIT— every nav still does a round-trip just for a 304.Adds a single
headers()rule innext.config.mjs:/_next/static,/_next/image,/api/*:public, max-age=0, s-maxage=300, stale-while-revalidate=86400— browser revalidates each nav, edge caches 5 min fresh + 24 h SWR./_next/static/*: untouched. Next.js setspublic, max-age=31536000, immutableand that header CANNOT be overridden innext.config.jsper Next.js docs./_next/image: untouched (image optimizer applies its own cache headers)./api/*: untouched (app-controlled per route).This repo has no
public/directory so there are no unhashed brand assets to configure separately.Vendor-doc check
{source, headers: [{key, value}]}confirmed./((?!_next/static|_next/image|api/).*)is the canonical Next.js form (see proxy negative-matching example in same docs).s-maxage+stale-while-revalidatesemantics for cache TTL and background revalidation.Expected impact
_next/static/*retainsimmutable(no change).Out of scope (separate PRs)
*.moleculesai.app.Test plan
curl -sI https://docs.moleculesai.app/ | grep -i cache-controlshowss-maxage=300, stale-while-revalidate=86400.curl -sI https://docs.moleculesai.app/docs/google-adk | grep -i cache-controlsame.curl -sI https://docs.moleculesai.app/_next/static/<chunk>.js | grep -i cache-controlstillimmutable, max-age=31536000.x-vercel-cache: HITafter first request.next buildsucceeds locally with new config (CI on Vercel will validate).RFC: internal#562 (step 1)
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com
docs#56 next.config.mjs Cache-Control addition for HTML pages only. Negative lookahead excludes _next internals + /api/ routes (auth-bearing). No secrets/auth-state cached. Security APPROVE.
docs#56 RFC#562 step 1: Next.js next.config.mjs headers() async fn — HTML pages s-maxage=300 SWR=86400, _next/static + _next/image + /api/ excluded via negative lookahead (preserves immutable hash-named caching). Clean diff. core-devops APPROVE.