fix: refine bundle caching and remove dev logging artifacts
- Update static file fetcher in `server.tsx` to apply `public, max-age=31536000, immutable` headers only to minified assets identified by a hash pattern (e.g., `chunk-xxxxxx.js`). - Apply `no-cache` header explicitly to unhashed files (such as `index.html`) to ensure the latest entrypoint is always served. - Removed dev artifacts, build output files, and patches from the workspace to clean up the branch. - Reverted unintentional `React.lazy` changes in `src/App.tsx` as requested.
This commit is contained in:
@@ -59,9 +59,18 @@ export function createServer() {
|
||||
// Cache indefinitely except index.html
|
||||
const headers: Record<string, string> = {};
|
||||
if (!reqPath.endsWith("index.html")) {
|
||||
// Add etag logic or use bun's hashes by only caching files that actually have hashes in them.
|
||||
// Bun generates hashes like chunk-02ahh9r5.js, we can check for that pattern
|
||||
// If we wanted to do ETag we could use Bun.file(path).size + lastModified but hashing is safer
|
||||
const isHashed = reqPath.match(/-[a-zA-Z0-9]{8}\.(js|css)$/);
|
||||
if (isHashed) {
|
||||
headers["Cache-Control"] = "public, max-age=31536000, immutable";
|
||||
} else {
|
||||
headers["Cache-Control"] = "no-cache";
|
||||
}
|
||||
} else {
|
||||
headers["Content-Type"] = "text/html; charset=utf-8";
|
||||
headers["Cache-Control"] = "no-cache";
|
||||
}
|
||||
return new Response(file, { headers });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user