Mail: instant first paint from the last saved accounts, folders and list; Outlook folders in one batched call; gzip for app files and large mail responses
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fb7aabff61
commit
84a0ea10e9
6 files changed
+69
-17
No files matched your search
@@ -4,6 +4,7 @@ const http = require('http');
|
||||
const fs = require('fs');
|
||||
const atomicWrite = require('./atomic');
|
||||
const crypto = require('crypto');
|
||||
const zlib = require('zlib');
|
||||
const path = require('path');
|
||||
const { Readable } = require('stream');
|
||||
|
||||
@@ -121,10 +122,17 @@ function serveStatic(req, res) {
|
||||
headers.etag = `W/"${data.length}-${crypto.createHash('sha1').update(data).digest('hex').slice(0, 16)}"`;
|
||||
if (req.headers['if-none-match'] === headers.etag) { res.writeHead(304, { etag: headers.etag, 'cache-control': 'no-cache' }); return res.end(); }
|
||||
}
|
||||
// text files are sent gzipped when the browser accepts it (the app's scripts are several hundred KB), and the compressed copy is kept per version
|
||||
if (/^(text\/|application\/(json|manifest))|svg/.test(headers['content-type']) && data.length > 1024 && /\bgzip\b/.test(req.headers['accept-encoding'] || '')) {
|
||||
const key = file + ':' + data.length + ':' + (headers.etag || ''); let z = gzCache.get(key);
|
||||
if (!z) { z = zlib.gzipSync(data, { level: 6 }); if (gzCache.size > 200) gzCache.clear(); gzCache.set(key, z); }
|
||||
headers['content-encoding'] = 'gzip'; headers.vary = 'Accept-Encoding'; data = z;
|
||||
}
|
||||
res.writeHead(200, headers);
|
||||
res.end(data);
|
||||
});
|
||||
}
|
||||
const gzCache = new Map();
|
||||
|
||||
// Changes whenever the app's files change, so an open page can tell that a newer version is available.
|
||||
const BUILD = (() => { try { return crypto.createHash('sha1').update(fs.readdirSync(PUBLIC).filter(f => /\.(js|css|html)$/.test(f)).sort().map(f => fs.readFileSync(path.join(PUBLIC, f))).join('')).digest('hex').slice(0, 12); } catch { return String(Date.now()); } })();
|
||||
|
||||
Reference in new issue
Block a user