Fix: sidebar.html charge une seule fois au lieu de deux sur toutes les pages
Reduit de 3 a 2 les fetch au DOMContentLoaded, liberant un slot de connexion HTTP. Corrige le blocage "pending" cause par la limite de 6 connexions simultanees par domaine dans Chrome/Firefox. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -108,34 +108,37 @@
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const elementsToLoad = [
|
||||
{ id: 'topbar', file: 'topbar.html' },
|
||||
{ id: 'sidebar', file: 'sidebar.html' },
|
||||
{ id: 'sidebar_mobile', file: 'sidebar.html' }
|
||||
];
|
||||
// Load topbar
|
||||
fetch('topbar.html')
|
||||
.then(r => r.text())
|
||||
.then(data => {
|
||||
document.getElementById('topbar').innerHTML = data;
|
||||
if (window.i18n && typeof window.i18n.applyTranslations === 'function') {
|
||||
window.i18n.applyTranslations();
|
||||
}
|
||||
})
|
||||
.catch(e => console.error('Error loading topbar:', e));
|
||||
|
||||
elementsToLoad.forEach(({ id, file }) => {
|
||||
fetch(file)
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
const element = document.getElementById(id);
|
||||
if (element) {
|
||||
element.innerHTML = data;
|
||||
// Apply translations after loading dynamic content
|
||||
if (window.i18n && typeof window.i18n.applyTranslations === 'function') {
|
||||
window.i18n.applyTranslations();
|
||||
}
|
||||
// Ensure the screen tab is visible here as well
|
||||
if (id.includes('sidebar')) {
|
||||
setTimeout(() => {
|
||||
const navScreenElements = element.querySelectorAll('.nav-screen-item');
|
||||
navScreenElements.forEach(el => el.style.display = 'flex');
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => console.error(`Error loading ${file}:`, error));
|
||||
});
|
||||
// Load sidebar once, reuse for desktop + mobile
|
||||
fetch('sidebar.html')
|
||||
.then(r => r.text())
|
||||
.then(data => {
|
||||
const sidebar = document.getElementById('sidebar');
|
||||
const sidebarMobile = document.getElementById('sidebar_mobile');
|
||||
sidebar.innerHTML = data;
|
||||
sidebarMobile.innerHTML = data;
|
||||
if (window.i18n && typeof window.i18n.applyTranslations === 'function') {
|
||||
window.i18n.applyTranslations();
|
||||
}
|
||||
// Ensure the screen tab is visible in both sidebars
|
||||
setTimeout(() => {
|
||||
[sidebar, sidebarMobile].forEach(el => {
|
||||
const navScreenElements = el.querySelectorAll('.nav-screen-item');
|
||||
navScreenElements.forEach(item => item.style.display = 'flex');
|
||||
});
|
||||
}, 100);
|
||||
})
|
||||
.catch(e => console.error('Error loading sidebar:', e));
|
||||
|
||||
// Translation fallback for now if keys are missing
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user