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

+76 -3
Voir le fichier
@@ -111,6 +111,11 @@
}
</script>
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 500 500'%3E%3Ccircle cx='250' cy='250' r='230' fill='%23111'/%3E%3Cpath d='M 80 280 L 170 210 L 210 230 L 250 140 L 290 190 L 330 160 L 420 280' fill='none' stroke='%23fff' stroke-width='24' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E">
<script data-inline>
// Niveau réseau -> <html data-net="low|mid|high"> (Network Information API,
// Chromium uniquement ; ailleurs : high). low = slow-2g, 2g ou économie de données.
(function(){var d=document.documentElement,c=navigator.connection;function t(){var e=c&&c.effectiveType;d.setAttribute('data-net',(c&&c.saveData)||e==='slow-2g'||e==='2g'?'low':e==='3g'?'mid':'high');}t();if(c&&c.addEventListener)c.addEventListener('change',t);})();
</script>
<link rel="preload" href="assets/fonts/inter-latin.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" as="image" href="assets/img/dji-fly-20250919-194610-0004-1758304172909-photo.webp" fetchpriority="high">
<style>
@@ -309,6 +314,8 @@ body.spa-nav-hidden .spa-nav { display:none; }
#custom-cursor.hovered.cursor-light { background:rgba(255,255,255,.15); }
#loader-wrapper { position:fixed; top:0; left:0; width:100%; height:100%; background:#fff; z-index:99999; display:flex; justify-content:center; align-items:center; transition:opacity .8s cubic-bezier(.77,0,.175,1),visibility .8s; }
#loader-wrapper.fade-out { opacity:0; visibility:hidden; }
.fragment-status { min-height:60vh; display:flex; align-items:center; justify-content:center; gap:12px; flex-wrap:wrap; padding:120px 20px; text-align:center; color:#666; font-family:var(--font-sans); }
.fragment-retry { padding:8px 18px; border:1px solid #111; border-radius:4px; background:#fff; color:#111; font:inherit; cursor:pointer; }
.custom-loader-container { width:180px; height:180px; display:flex; justify-content:center; align-items:center; animation:custom-loader-pulse 2.5s infinite ease-in-out; }
@keyframes custom-loader-pulse { 0%,100%{transform:scale(.92);opacity:.8;} 50%{transform:scale(1.05);opacity:1;} }
@@ -2684,6 +2691,7 @@ body.spa-nav-hidden .spa-nav { display:none; }
(function(){
'use strict';
var reduceMotion=!!(window.matchMedia&&window.matchMedia('(prefers-reduced-motion: reduce)').matches);
function netTier(){ return document.documentElement.getAttribute('data-net')||'high'; }
var ROUTES=['accueil','portfolio','realisations','apropos','apps','application','gws','telechargement','deroulement','termes','news','carnet'];
var LEGAL_TABS={'termes':'home','legal':'home','legal-cgv':'cgv','legal-rgpd':'rgpd','legal-mentions':'mentions'};
function showLegalTab(tab){
@@ -2869,7 +2877,63 @@ function reveal(scope){
},{threshold:0.1,rootMargin:'0px 0px -20px 0px'});
els.forEach(function(el){ el.classList.remove('active'); revealObs.observe(el); });
}
// Sections externalisées par le build (attribut data-fragment) : chargées à la
// demande, mises en cache (mémoire + HTTP immutable).
var fragCache={};
function fetchFragment(url){
if(!fragCache[url]){
fragCache[url]=fetch(url).then(function(r){ if(!r.ok) throw new Error('HTTP '+r.status); return r.text(); })
.catch(function(e){ delete fragCache[url]; throw e; });
}
return fragCache[url];
}
function loadFragment(sec,asked){
return fetchFragment(sec.getAttribute('data-fragment')).then(function(html){
sec.innerHTML=html; sec.removeAttribute('data-fragment');
if((location.hash.replace('#','')||DEFAULT)===asked) go(asked);
},function(){
sec.innerHTML='<p class="fragment-status">Impossible de charger cette page. <button type="button" class="fragment-retry">Réessayer</button></p>';
sec.querySelector('.fragment-retry').addEventListener('click',function(){ go(asked); });
});
}
// Préchargement selon le réseau : high = au repos après le chargement,
// mid = à l'intention (survol, focus, toucher d'un lien), low = au clic seulement.
function prefetchFragments(){
var secs=[].slice.call(document.querySelectorAll('.spa-section[data-fragment]'));
if(!secs.length) return;
var tier=netTier();
if(tier==='high'){
var run=function(){ secs.forEach(function(s){ if(s.hasAttribute('data-fragment')) fetchFragment(s.getAttribute('data-fragment')).catch(function(){}); }); };
if(window.requestIdleCallback) requestIdleCallback(run,{timeout:4000}); else setTimeout(run,2500);
} else if(tier==='mid'){
var onIntent=function(e){
var a=e.target.closest&&e.target.closest('a[href^="#"]'); if(!a) return;
var r=a.getAttribute('href').slice(1);
var s=document.getElementById(LEGAL_TABS.hasOwnProperty(r)?'termes':r);
if(s&&s.hasAttribute('data-fragment')) fetchFragment(s.getAttribute('data-fragment')).catch(function(){});
};
['pointerover','focusin','touchstart'].forEach(function(t){ document.addEventListener(t,onIntent,{passive:true}); });
}
}
// Réseau lent : les images lazy hors écran attendent d'être réellement visibles
// (le lazy-loading natif charge, lui, jusqu'à ~2500 px à l'avance sur réseau lent).
function deferOffscreenImages(){
if(netTier()!=='low'||!('IntersectionObserver' in window)) return;
var io=new IntersectionObserver(function(entries){
entries.forEach(function(en){
if(!en.isIntersecting) return;
var img=en.target; img.setAttribute('src',img.getAttribute('data-src')); img.removeAttribute('data-src'); io.unobserve(img);
});
});
document.querySelectorAll('img[loading="lazy"][src]').forEach(function(img){
if(img.complete&&img.naturalWidth) return;
var r=img.getBoundingClientRect();
if(r.width&&r.bottom>0&&r.top<window.innerHeight) return;
img.setAttribute('data-src',img.getAttribute('src')); img.removeAttribute('src'); io.observe(img);
});
}
function go(route){
var asked=route;
var legalTab=LEGAL_TABS.hasOwnProperty(route)?LEGAL_TABS[route]:null;
var legalHash=route;
var targetScroll=null;
@@ -2886,6 +2950,12 @@ function go(route){
if(!sec) return;
sec.classList.add('active');
if(nav) nav.classList.add('active');
if(sec.hasAttribute('data-fragment')){
document.body.classList.toggle('spa-nav-hidden', route==='accueil'||route==='termes');
window.scrollTo(0,0); switchAnim(route);
loadFragment(sec,asked);
return;
}
document.body.classList.toggle('spa-accueil-cursor', route==='accueil');
document.body.classList.toggle('spa-nav-hidden', route==='accueil'||route==='termes');
window.scrollTo(0,0);
@@ -3074,7 +3144,7 @@ var Modules={
track.style.transform='translateX(-'+(currentIndex*100)+'%)';
root.style.setProperty('--accent-theme',themes[currentIndex]);
carouselWindow.classList.add('slide-portfolio-active');
loadSlideBg(currentIndex); preloadNextBg(currentIndex+1);
loadSlideBg(currentIndex); if(netTier()!=='low') preloadNextBg(currentIndex+1);
triggerScramble(slides[currentIndex]);
}
var PP_PAUSE={v:'0 0 320 512',d:'M48 64C21.5 64 0 85.5 0 112V400c0 26.5 21.5 48 48 48H80c26.5 0 48-21.5 48-48V112c0-26.5-21.5-48-48-48H48zm192 0c-26.5 0-48 21.5-48 48V400c0 26.5 21.5 48 48 48h32c26.5 0 48-21.5 48-48V112c0-26.5-21.5-48-48-48H240z'};
@@ -3082,8 +3152,9 @@ var Modules={
function applyPPIcon(ic){ if(!playPauseIcon) return; playPauseIcon.setAttribute('viewBox',ic.v); var p=playPauseIcon.querySelector('path'); if(p) p.setAttribute('d',ic.d); }
function togglePlay(){ isPaused=!isPaused; applyPPIcon(isPaused?PP_PLAY:PP_PAUSE); }
playPauseBtn.addEventListener('click',togglePlay);
// Mouvement réduit ou mode économie de données : pas de défilement automatique.
if(reduceMotion||(navigator.connection&&navigator.connection.saveData)){ isPaused=true; applyPPIcon(PP_PLAY); }
// Mouvement réduit ou réseau lent / économie de données : pas de défilement
// automatique (chaque slide charge une grande image de fond).
if(reduceMotion||netTier()==='low'){ isPaused=true; applyPPIcon(PP_PLAY); }
function triggerCrossShake(){ if(modalCross){ modalCross.classList.remove('shake-active'); void modalCross.offsetWidth; modalCross.classList.add('shake-active'); setTimeout(function(){ modalCross.classList.remove('shake-active'); },2000); } }
if(storeModal && openStoreBtn){
initModal(storeModal,{
@@ -3799,6 +3870,8 @@ function boot(){
var loader=document.getElementById('loader-wrapper');
scrollLock.lock();
go(location.hash.replace('#','')||DEFAULT);
deferOffscreenImages();
if(document.readyState==='complete') prefetchFragments(); else window.addEventListener('load',prefetchFragments);
// Écran de chargement : retiré dès que le minimum est prêt (polices du haut
// de page + image préchargée du carrousel), au plus tard après 1150 ms.
var hidden=false;
+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}`);
}