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:
@@ -1279,6 +1279,10 @@ func (s *Server) handleTranslationRead(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Translated chapter content is immutable once generated — cache aggressively.
|
||||||
|
// The browser and any intermediary (CDN, SvelteKit fetch cache) can reuse this
|
||||||
|
// response for 1 hour without hitting MinIO again.
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=3600, stale-while-revalidate=86400")
|
||||||
writeJSON(w, 0, map[string]string{"html": buf.String(), "lang": lang})
|
writeJSON(w, 0, map[string]string{"html": buf.String(), "lang": lang})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,12 @@ export const GET: RequestHandler = async ({ params, url }) => {
|
|||||||
return new Response(null, { status: res.status });
|
return new Response(null, { status: res.status });
|
||||||
}
|
}
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
return new Response(JSON.stringify(data), {
|
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
||||||
headers: { '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 }) => {
|
export const POST: RequestHandler = async ({ params, url, locals }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user