//footer (function() { function addFooterContent() { var footerContainer = document.querySelector(".copyright-text"); if (footerContainer && !footerContainer.querySelector(".extra-footer-content")) { var newContent = document.createElement("span"); newContent.classList.add("extra-footer-content"); newContent.innerHTML = ' Run by: ' + 'Skylight'; footerContainer.appendChild(newContent); } } addFooterContent(); })(); document.addEventListener("DOMContentLoaded", () => { /*** ✅ تحسين تحميل الصور Lazy Loading بدون تخريب ***/ document.querySelectorAll("img:not(.no-lazy)").forEach(img => { img.setAttribute("loading", "lazy"); img.setAttribute("decoding", "async"); img.style.display = "block"; // منع CLS }); /*** ✅ تحميل الخطوط مسبقًا لضمان سرعة التحميل ***/ const fonts = [ "/fonts/harir-regular.woff2", "/fonts/harir-bold.woff2" ]; fonts.forEach(font => { const link = document.createElement("link"); link.rel = "preload"; link.href = font; link.as = "font"; link.type = "font/woff2"; link.crossOrigin = "anonymous"; document.head.appendChild(link); }); /*** ✅ تحميل سكربتات الطرف الثالث بعد تحميل الصفحة ***/ window.addEventListener("load", () => { const thirdPartyScripts = [ "https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.js", "/scripts/some-script.js" ]; thirdPartyScripts.forEach(src => { const script = document.createElement("script"); script.src = src; script.async = true; // يمنع تأخير تحميل الصفحة document.body.appendChild(script); }); }); /*** ✅ تحسين CLS عبر تحديد أبعاد الصور فقط في حال عدم وجودها ***/ document.querySelectorAll("img").forEach(img => { if (!img.hasAttribute("width") || !img.hasAttribute("height")) { img.setAttribute("width", img.naturalWidth || 300); img.setAttribute("height", img.naturalHeight || 300); } }); /*** ✅ تأجيل تحميل JavaScript غير الضروري ***/ document.querySelectorAll("script[src]").forEach(script => { script.defer = true; }); /*** ✅ تسجيل Service Worker لتحميل أسرع ***/ if ("serviceWorker" in navigator) { navigator.serviceWorker.register("/sw.js") .then(() => console.log("✅ Service Worker Registered")) .catch(error => console.error("❌ Service Worker Failed:", error)); } });