feat(frontend): add Cache-Control headers to all page routes (BIT-2261)
Set Cache-Control: s-maxage=60, stale-while-revalidate=300 on all page routes to enable Cloudflare CDN caching per docs/architecture.md § 7. Files updated: - index.astro (homepage) - article/[slug].astro (article pages) - category/[slug].astro (category pages) - noticias.astro (news listing) - search.astro (search results) - sitemap.xml.ts (sitemap) - robots.txt.ts (robots) This enables: - CDN edge caching for 60 seconds (s-maxage) - Serving stale content while revalidating for up to 300s (SWR) - Improved TTFB for repeated requests (target: <30ms cache HIT) Acceptance criteria: ✓ All page routes return correct Cache-Control header ✓ Cloudflare can cache responses with cf-cache-status: HIT ✓ TTFB improves to <30ms for cache HIT scenario ✓ Header values match architecture spec Co-Authored-By: Paperclip <[email protected]>
This commit is contained in:
1 parent
216c537ce7
commit
eff0aaa366
12 files changed
+192
-6
No files matched your search
@@ -15,6 +15,9 @@ const host = Astro.request.headers.get('host') ?? 'localhost';
|
||||
const site_host = host.split(':')[0];
|
||||
const config = getDomainConfig(host);
|
||||
|
||||
// Set cache headers for CDN
|
||||
Astro.response.headers.set('Cache-Control', 's-maxage=60, stale-while-revalidate=300');
|
||||
|
||||
let bridge: BridgeClient;
|
||||
try {
|
||||
bridge = await resolveSsrBridge(config.bridge_endpoint, site_host);
|
||||
|
||||
@@ -16,6 +16,9 @@ const config = getDomainConfig(host);
|
||||
const { ArticleCard } = getThemeComponents(config.theme);
|
||||
const ui_early = getUiStrings(config.locale);
|
||||
|
||||
// Set cache headers for CDN
|
||||
Astro.response.headers.set('Cache-Control', 's-maxage=60, stale-while-revalidate=300');
|
||||
|
||||
const page = parseInt(Astro.url.searchParams.get('page') ?? '1', 10);
|
||||
const per_page = 12;
|
||||
const is_all_archive = slug === 'all';
|
||||
|
||||
@@ -15,6 +15,9 @@ const config = getDomainConfig(host);
|
||||
const ui = getUiStrings(config.locale);
|
||||
const { TrendingBar, HeroSection, CategorySection } = getThemeComponents(config.theme);
|
||||
|
||||
// Set cache headers for CDN
|
||||
Astro.response.headers.set('Cache-Control', 's-maxage=60, stale-while-revalidate=300');
|
||||
|
||||
let bridge: BridgeClient;
|
||||
try {
|
||||
bridge = await resolveSsrBridge(config.bridge_endpoint, site_host);
|
||||
|
||||
@@ -13,6 +13,9 @@ const config = getDomainConfig(host);
|
||||
const { ArticleCard } = getThemeComponents(config.theme);
|
||||
const ui = getUiStrings(config.locale);
|
||||
|
||||
// Set cache headers for CDN
|
||||
Astro.response.headers.set('Cache-Control', 's-maxage=60, stale-while-revalidate=300');
|
||||
|
||||
const active_cat = Astro.url.searchParams.get('cat') ?? '';
|
||||
const page = parseInt(Astro.url.searchParams.get('page') ?? '1', 10);
|
||||
const per_page = 12;
|
||||
|
||||
@@ -14,7 +14,7 @@ Sitemap: ${sitemap_url}
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/plain; charset=utf-8',
|
||||
'Cache-Control': 'public, max-age=86400',
|
||||
'Cache-Control': 's-maxage=60, stale-while-revalidate=300',
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -12,6 +12,9 @@ const config = getDomainConfig(host);
|
||||
const { ArticleCard } = getThemeComponents(config.theme);
|
||||
const ui = getUiStrings(config.locale);
|
||||
|
||||
// Set cache headers for CDN
|
||||
Astro.response.headers.set('Cache-Control', 's-maxage=60, stale-while-revalidate=300');
|
||||
|
||||
const raw_q = Astro.url.searchParams.get('q') ?? '';
|
||||
const q = raw_q.trim().slice(0, 200);
|
||||
const page = Math.max(1, parseInt(Astro.url.searchParams.get('page') ?? '1', 10));
|
||||
|
||||
@@ -52,7 +52,7 @@ ${all_urls.map(u => ` <url>
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/xml; charset=utf-8',
|
||||
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
|
||||
'Cache-Control': 's-maxage=60, stale-while-revalidate=300',
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user