From af69a189e3db348ac8b4d0e2c75fb9ec7e847dee Mon Sep 17 00:00:00 2001 From: Paul Bakaus Date: Thu, 12 Mar 2026 11:26:28 -0700 Subject: [PATCH] perf: add cache headers for static assets on Cloudflare Pages - Hashed JS/CSS bundles: immutable, 1 year cache - Images/logos/SVGs: 1 week cache with 1 day stale-while-revalidate - HTML pages: browser revalidates, CDN caches 1h - ZIP downloads: 1h cache - API routes: unchanged (CDN 24h) Co-Authored-By: Claude Opus 4.6 --- scripts/build.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/scripts/build.js b/scripts/build.js index 0a37905e6..2e51691b6 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -245,6 +245,45 @@ function generateCFConfig(buildDir) { X-Content-Type-Options: nosniff X-Frame-Options: DENY +# HTML pages: browser always revalidates, CDN caches 1h +/*.html + Cache-Control: public, max-age=0, s-maxage=3600, stale-while-revalidate=600 + +# Hashed JS/CSS bundles: immutable (filename changes on content change) +/assets/*.js + Cache-Control: public, max-age=31536000, immutable + +/assets/*.css + Cache-Control: public, max-age=31536000, immutable + +# Static images and logos: 1 week + 1 day stale +/assets/*.png + Cache-Control: public, max-age=604800, stale-while-revalidate=86400 + +/assets/*.svg + Cache-Control: public, max-age=604800, stale-while-revalidate=86400 + +/assets/*.webp + Cache-Control: public, max-age=604800, stale-while-revalidate=86400 + +/antipattern-images/* + Cache-Control: public, max-age=604800, stale-while-revalidate=86400 + +# Root static assets (favicon, og-image, etc.) +/favicon.svg + Cache-Control: public, max-age=604800, stale-while-revalidate=86400 + +/og-image.jpg + Cache-Control: public, max-age=604800, stale-while-revalidate=86400 + +/apple-touch-icon.png + Cache-Control: public, max-age=604800, stale-while-revalidate=86400 + +# ZIP downloads: 1h cache +/dist/*.zip + Cache-Control: public, max-age=3600, stale-while-revalidate=600 + +# API routes: CDN caches 24h /api/* Cache-Control: public, s-maxage=86400, stale-while-revalidate=3600