This commit is contained in:
Julie Blanc 2026-02-27 20:33:56 +01:00
parent 25cdb3bd0b
commit 31e1b729f3
28 changed files with 925 additions and 426 deletions

View file

@ -527,35 +527,44 @@
<!-- SCRIPTÀSUPPRIMERUNEFOISLESITEINTEGRÉ (include des composants)-->
<script>
function processIncludes() {
const includes = document.querySelectorAll('include[src]');
async function processIncludes(maxDepth = 5) {
let depth = 0;
if (includes.length === 0) {
return;
}
while (depth < maxDepth) {
const includes = document.querySelectorAll('include[src]');
if (includes.length === 0) break;
const promises = Array.from(includes).map(el => {
const src = el.getAttribute('src');
return fetch(src)
.then(r => {
if (!r.ok) throw new Error(`Erreur ${r.status}: ${src}`);
return r.text();
})
.then(html => {
el.outerHTML = html;
})
.catch(err => {
console.error('Erreur de chargement:', err);
});
});
const promises = Array.from(includes).map(async el => {
const src = el.getAttribute('src');
Promise.all(promises).then(() => {
processIncludes();
});
}
try {
const response = await fetch(src, { cache: "no-store" });
if (!response.ok) throw new Error(response.status);
const html = await response.text();
el.outerHTML = html;
} catch (err) {
console.error("Erreur include:", src, err);
}
});
document.addEventListener('DOMContentLoaded', processIncludes);
await Promise.all(promises);
// Petite pause pour éviter rafale ultra rapide
await new Promise(r => setTimeout(r, 50));
depth++;
}
if (depth === maxDepth) {
console.warn("Max include depth reached (possible boucle).");
}
}
document.addEventListener("DOMContentLoaded", () => {
processIncludes();
});
</script>
</body>
</html>