Phase 2 perf : #termes en fragment charge a la demande, niveaux reseau (Network Information API) pour prechargement, images et carrousel

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
Théo GastineletClaude Opus 5.5 a révisé 2026-10-12 16:24:13 +02:00
1 Parent 5195e5b884
révision 3f8c39ba87
3 fichiers modifiés
+94 -5

Aucun fichier ne correspond à votre recherche

+17 -1
Voir le fichier
@@ -10,6 +10,7 @@
* - assets/build/app.<hash>.css tous les <style> regroupés + minifiés
* - assets/build/app.<hash>.js le script principal, chargé en defer
* - assets/build/<police>.<hash>.woff2 polices renommées (cache immutable)
* - assets/build/<section>.<hash>.html sections chargées à la demande (FRAGMENTS)
* - llms.txt, robots.txt, sitemap.xml, data/news.json
* - un .br et un .gz pour chaque fichier texte (Caddy: precompressed br gzip)
* - build-manifest.json liste des fichiers + empreintes (utilisé par deploy.js)
@@ -27,7 +28,9 @@ const crypto = require('crypto');
const ROOT = path.resolve(__dirname, '..');
const DIST = path.join(ROOT, 'dist');
const BUILD_DIR = 'assets/build';
const COPY_AS_IS = ['llms.txt', 'robots.txt', 'sitemap.xml', 'data/news.json'];
// Sections retirées du HTML initial (lourdes, peu utiles au référencement).
const FRAGMENTS = ['termes'];
const COPY_AS_IS =['llms.txt', 'robots.txt', 'sitemap.xml', 'data/news.json'];
const COMPRESSIBLE = new Set(['.html', '.css', '.js', '.json', '.txt', '.xml', '.svg']);
const hash = (buf) => crypto.createHash('sha256').update(buf).digest('hex').slice(0, 10);
@@ -124,6 +127,19 @@ function build() {
html = html.replace('<!--@@CSS@@-->',
`<link rel="stylesheet" href="${cssPath}">\n<script src="${jsPath}" defer></script>\n`);
// 3b. Sections externalisées : leur contenu part dans un fragment chargé à la
// demande par le routeur (go -> loadFragment). Section de niveau 0 : se
// termine par "\n</section>" en début de ligne.
for (const id of FRAGMENTS) {
const re = new RegExp(`(<section id="${id}" class="spa-section")>([\\s\\S]*?)\\n</section>\\n`);
const m = html.match(re);
if (!m) throw new Error(`Section #${id} introuvable pour le fragment.`);
if (/<script|<style/i.test(m[2])) throw new Error(`#${id} contient du script/style inline.`);
const frag = minifyHtml(m[2]);
const fragPath = emit(`${BUILD_DIR}/${id}.${hash(frag)}.html`, frag);
html = html.replace(re, `$1 data-fragment="${fragPath}"><p class="fragment-status">Chargement…</p></section>\n`);
}
// 4. JSON-LD compacté.
html = html.replace(/(<script type="application\/ld\+json">)([\s\S]*?)(<\/script>)/,
(m, a, json, b) => a + JSON.stringify(JSON.parse(json)) + b);
+1 -1
Voir le fichier
@@ -120,7 +120,7 @@ async function verify(manifest) {
if (md5(body) !== manifest.files['index.html']) {
throw new Error(`Vérification : le HTML servi ne correspond pas au build (encodage ${enc}).`);
}
for (const f of Object.keys(manifest.files).filter((f) => /^assets\/build\/[^/]+\.(css|js|woff2)$/.test(f))) {
for (const f of Object.keys(manifest.files).filter((f) => /^assets\/build\/[^/]+\.(css|js|woff2|html)$/.test(f))) {
const r = await fetch(`${SITE}/${f}`, { method: 'HEAD' });
if (!r.ok) throw new Error(`Vérification : ${f} -> HTTP ${r.status}`);
}