Precompress the bundle, validate the shell, and pass byte ranges on
The web build now writes a Brotli and a gzip copy of each compressible file, and the static handler serves the best one the browser accepts. The bundle was gzipped again for every request and Brotli was never offered; the main chunk is 122 KB with Brotli against 144 KB gzipped. index.html and every static file carry an ETag, and a matching If-None-Match gets a 304. The shell and the worker are revalidated on every load and were downloaded whole each time. Attachment downloads pass a plain byte Range to Stalwart and relay a 206, so a PDF viewer or a video element can read in pieces where the server allows it. On the reader's own device a blob is cached as immutable, since its id names its content. The upstream session and account-info caches drop entries past their age on a timer; they lost an entry only on sign-out or refusal, not when a session expired. The mock answers byte ranges.
This commit is contained in:
@@ -138,7 +138,21 @@ export const server = createServer(async (req, res) => {
|
||||
const [, , , , blobId] = url.pathname.split("/");
|
||||
const b = blobs.get(blobId ?? "");
|
||||
if (!b) { res.writeHead(404); return res.end(); }
|
||||
res.writeHead(200, { "content-type": url.searchParams.get("accept") ?? b.type, "content-length": b.data.length });
|
||||
const type = url.searchParams.get("accept") ?? b.type;
|
||||
// One byte range, the way a PDF viewer or a video element asks for one.
|
||||
const m = /^bytes=(\d*)-(\d*)$/.exec(String(req.headers.range ?? ""));
|
||||
if (m && (m[1] || m[2])) {
|
||||
const size = b.data.length;
|
||||
const start = m[1] ? Number(m[1]) : Math.max(0, size - Number(m[2]));
|
||||
const end = m[1] && m[2] ? Math.min(Number(m[2]), size - 1) : size - 1;
|
||||
if (start >= size || start > end) {
|
||||
res.writeHead(416, { "content-range": `bytes */${size}` });
|
||||
return res.end();
|
||||
}
|
||||
res.writeHead(206, { "content-type": type, "content-length": end - start + 1, "content-range": `bytes ${start}-${end}/${size}`, "accept-ranges": "bytes" });
|
||||
return res.end(b.data.subarray(start, end + 1));
|
||||
}
|
||||
res.writeHead(200, { "content-type": type, "content-length": b.data.length, "accept-ranges": "bytes" });
|
||||
return res.end(b.data);
|
||||
}
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user