perf: optimize branded 404 artwork
This commit is contained in:
@@ -24,6 +24,9 @@ const REQUEST_MAX_BYTES = 6 * 1024 * 1024;
|
||||
const API_READ_LIMIT_PER_MINUTE = 120;
|
||||
const MEDIA_READ_LIMIT_PER_MINUTE = 600;
|
||||
const SSE_HEARTBEAT_MS = 25_000;
|
||||
const IMMUTABLE_CACHE_CONTROL = 'public, max-age=31536000, immutable';
|
||||
const REVALIDATING_CACHE_CONTROL = 'public, max-age=300, must-revalidate';
|
||||
const FINGERPRINTED_ASSET = /\.[a-f0-9]{8,}\.[a-z0-9]+$/i;
|
||||
const events = new Set();
|
||||
const DISCOVERY_ROUTES = new Set([
|
||||
'/openapi.json',
|
||||
@@ -152,6 +155,8 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && url.pathname.startsWith('/assets/')) {
|
||||
const isVersioned = url.searchParams.has('v') || FINGERPRINTED_ASSET.test(url.pathname);
|
||||
res.setHeader('Cache-Control', isVersioned ? IMMUTABLE_CACHE_CONTROL : REVALIDATING_CACHE_CONTROL);
|
||||
return sendFile(res, `./public${url.pathname}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user