perf: cache translated chapter responses for 1 hour

Translation content is immutable once generated — add Cache-Control: public,
max-age=3600, stale-while-revalidate=86400 to handleTranslationRead so the
browser and any CDN reuse the response without hitting MinIO on repeat views.
Forward the header through the SvelteKit /api/translation/[slug]/[n] proxy
which previously stripped it by constructing a bare Content-Type-only Response.
This commit is contained in:
root
2026-04-13 21:34:02 +05:00
parent 708f8bcd6f
commit 734ba68eed
2 changed files with 10 additions and 3 deletions

View File

@@ -23,9 +23,12 @@ export const GET: RequestHandler = async ({ params, url }) => {
return new Response(null, { status: res.status });
}
const data = await res.json();
return new Response(JSON.stringify(data), {
headers: { 'Content-Type': 'application/json' }
});
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
// Forward the immutable cache header from the backend so browsers and CDNs
// can cache translated chapter content without hitting MinIO on every load.
const cc = res.headers.get('Cache-Control');
if (cc) headers['Cache-Control'] = cc;
return new Response(JSON.stringify(data), { headers });
};
export const POST: RequestHandler = async ({ params, url, locals }) => {