-
Notifications
You must be signed in to change notification settings - Fork 108
Open
Description
When this library loads a database file, it does a HEAD to get the total length of the database file. On some dev servers the etag is calculated, which in turns reads the entire database file. For large databases this is very slow, on the order of seconds.
I found this to be the case when using vite on windows. I wrote a small vite plugin which intercepts these HEAD calls and just returns Content-Length
import fs from "node:fs";
const SkipHeadEtag = () => ({
name: "skip-head-etag",
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.method === "HEAD") {
const { size } = fs.statSync(req.url.slice(1));
res.setHeader("Accept-Ranges", "bytes");
res.setHeader("Cache-Control", "no-cache");
res.setHeader("Content-Length", String(size));
res.end();
return;
}
next();
});
},
});That plugin is incomplete. It doesn't handle 404 properly, but shows the main idea of the workaround.
Metadata
Metadata
Assignees
Labels
No labels