feat: add static cache

This commit is contained in:
David Nguyen
2025-02-15 00:08:36 +11:00
parent 0f6f236e0c
commit 8d5fafec27
2 changed files with 14 additions and 2 deletions

View File

@ -16,6 +16,15 @@ import * as build from './index.js';
server.use(
serveStatic({
root: 'build/client',
onFound: (path, c) => {
if (path.startsWith('./build/client/assets')) {
// Hard cache assets with hashed file names.
c.header('Cache-Control', `public, immutable, max-age=31536000`);
} else {
// Cache with revalidation for rest of static files.
c.header('Cache-Control', 'no-cache, stale-while-revalidate');
}
},
}),
);