Cache-Warming: Bilder beim Serverstart vorab laden (sofortiges Erst-Rendering)
This commit is contained in:
@@ -125,3 +125,20 @@ const server = http.createServer(async (req, res) => {
|
||||
});
|
||||
|
||||
server.listen(PORT, () => console.log('Reise-Vergleich läuft auf Port ' + PORT + ' | Daten: ' + DATA_FILE));
|
||||
|
||||
// Prefetch all hotel/cruise images into the proxy cache so the first visit is instant.
|
||||
(async () => {
|
||||
let list = [];
|
||||
try { list = JSON.parse(fs.readFileSync(path.join(__dirname, 'warm-urls.json'), 'utf8')); }
|
||||
catch (e) { return; }
|
||||
for (const u of list) {
|
||||
try {
|
||||
const host = new URL(u).host;
|
||||
if (!hostAllowed(host) || imgCache.has(u)) continue;
|
||||
const referer = host.endsWith('ahoi-schiff.de') ? 'https://www.ahoi-schiff.de/' : 'https://urlaub.check24.de/';
|
||||
const r = await fetch(u, { headers: { 'Referer': referer, 'User-Agent': 'Mozilla/5.0 (compatible; HeidrichReise/1.0)', 'Accept': 'image/*' } });
|
||||
if (r.ok) imgCache.set(u, { buf: Buffer.from(await r.arrayBuffer()), type: r.headers.get('content-type') || 'image/jpeg' });
|
||||
} catch (e) { /* skip */ }
|
||||
}
|
||||
console.log('Bild-Cache vorgewärmt:', imgCache.size + '/' + list.length);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user