From a3fcacb212f4cc7247c74f177eef183af9baa0b6 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 00:32:42 +0200 Subject: [PATCH] Website: the new favicon reaches browsers at once, and /favicon.ico exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The icon files kept their names while the server lets browsers cache /favicon* for a week, so visitors still saw the old mark. The pages now link each icon with its content hash (?v=…), and the build writes /favicon.ico (the 32-pixel PNG in an ICO container) for browsers that ask for it on their own. Co-Authored-By: Claude Opus 5.5 --- website/build.mjs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/website/build.mjs b/website/build.mjs index 19451900e..6163d6307 100644 --- a/website/build.mjs +++ b/website/build.mjs @@ -122,6 +122,28 @@ await mkdir(join(dist, "assets"), { recursive: true }); await cp(join(site, "public"), dist, { recursive: true }); await cp(join(site, "LEGAL.md"), join(dist, "LEGAL.md")); +// The icons keep their names (browsers and other sites ask for /favicon.svg and the +// rest), so the pages link them with their content's hash: a new mark reaches everyone +// at once instead of after the week the server lets browsers keep the old one. +const iconVersions = {}; +for (const icon of ["favicon.svg", "favicon-32.png", "apple-touch-icon.png"]) { + iconVersions[icon] = fingerprint(await readFile(join(site, "public", icon))); +} +// /favicon.ico, which browsers request on their own: the 32-pixel PNG in an ICO +// container (one image entry; ICO has held PNG data since Windows Vista). +const png32 = await readFile(join(site, "public", "favicon-32.png")); +const ico = Buffer.alloc(22); +ico.writeUInt16LE(0, 0); // reserved +ico.writeUInt16LE(1, 2); // type: icon +ico.writeUInt16LE(1, 4); // one image +ico.writeUInt8(32, 6); // width +ico.writeUInt8(32, 7); // height +ico.writeUInt16LE(1, 10); // colour planes +ico.writeUInt16LE(32, 12); // bits per pixel +ico.writeUInt32LE(png32.length, 14); +ico.writeUInt32LE(22, 18); // the image follows the header and its entry +await writeFile(join(dist, "favicon.ico"), Buffer.concat([ico, png32])); + // The page's modules, fingerprinted; each import of a shared module is rewritten to its name. const names = {}; const rewrite = (code) => code.replace(/"\.\/(\w+\.js)"/g, (all, file) => (names[file] ? `"./${names[file]}"` : all)); @@ -184,6 +206,7 @@ for (const page of ["index.html", "404.html"]) { if (!(key in values)) throw new Error(`${page}: unknown placeholder ${all}`); return values[key]; }); + html = html.replace(/href="\/(favicon\.svg|favicon-32\.png|apple-touch-icon\.png)"/g, (all, icon) => `href="/${icon}?v=${iconVersions[icon]}"`); await writeFile(join(dist, page), html); }