Chat
top of page

Photo Gallery

Relais
Moorish House

Luxury holiday villa

bottom of page
/** * Script di Ottimizzazione Velocità Mobile per Wix - VERSIONE FINALE "ESSENTIAL" * POSIZIONE: Body - fine (Obbligatorio) * * OBIETTIVO: * 1. FIX RENDER BLOCKING: Carica le icone Font Awesome in modo asincrono (non rallentano l'avvio). * 2. CPU & LAYOUT: Gestisce SmartTarget/TrustIndex per evitare rallentamenti e strisce bianche. * 3. ICONE: Tutte le icone del sito rimangono visibili e funzionanti. */ (function() { // 1. CSS DI SOPPRESSIONE (Ottimizzato per evitare Layout Thrashing) var css = ` /* Nasconde i contenitori dello script */ .wix-custom-element, .custom-html-wrapper, [data-wix-custom-element] { display: none !important; height: 0 !important; width: 0 !important; overflow: hidden !important; } body { margin: 0 !important; padding: 0 !important; } /* ISOLAMENTO WIDGET PESANTI Usiamo position: absolute per toglierli dal flusso del documento e impedire che il calcolo delle loro dimensioni rallenti la pagina. */ [id*="smartarget"], #st-bar, .trustindex-content, iframe[src*="trustindex"], iframe[src*="smartarget"], iframe[src*="visitor-analytics"] { display: none !important; visibility: hidden !important; position: absolute !important; top: -9999px !important; left: -9999px !important; width: 1px !important; height: 1px !important; pointer-events: none !important; } /* Classe per riattivare i widget all'interazione */ .cpu-saver-active { display: block !important; visibility: visible !important; position: static !important; /* O relative, a seconda del widget */ width: auto !important; height: auto !important; top: auto !important; left: auto !important; pointer-events: auto !important; } /* Fix specifico per banner SmartTarget quando attivo */ .cpu-saver-active[id*="smartarget"] { position: relative !important; } `; var style = document.createElement('style'); style.id = "cpu-saver-css"; style.appendChild(document.createTextNode(css)); document.head.appendChild(style); })(); // 2. GESTORE INTELLIGENTE CPU (Congela SmartTarget/TrustIndex) (function() { let userActive = false; function unfreeze() { if (userActive) return; userActive = true; console.log("⚡ Utente attivo: Sblocco widget..."); // Invece di rimuovere il CSS, aggiungiamo una classe agli elementi // Questo è più performante che modificare i fogli di stile globali var widgets = document.querySelectorAll( '[id*="smartarget"], #st-bar, .trustindex-content, iframe[src*="trustindex"], iframe[src*="smartarget"]' ); widgets.forEach(function(el) { el.classList.add('cpu-saver-active'); }); // Rimuoviamo lo stile restrittivo dopo un attimo per sicurezza setTimeout(function() { var style = document.getElementById("cpu-saver-css"); if (style) { // Manteniamo solo la pulizia dei wrapper Wix style.textContent = ` .wix-custom-element, .custom-html-wrapper { display: none !important; } body { margin: 0 !important; padding: 0 !important; } `; } window.dispatchEvent(new Event('resize')); }, 200); } const events = ['mousedown', 'touchstart', 'scroll', 'mousemove', 'keydown']; events.forEach(ev => window.addEventListener(ev, unfreeze, { once: true, passive: true })); setTimeout(unfreeze, 4500); })(); // 3. GESTORE CSS SWAP (Il cuore della fix per Render Blocking - SALVA LE TUE ICONE!) (function() { try { const CSS_BLOCK = ['cdnjs.cloudflare.com', 'all.min.css']; function swapCSS(node) { if (node.tagName === 'LINK' && node.rel === 'stylesheet') { if (CSS_BLOCK.some(b => node.href.includes(b))) { // 1. Clona il nodo var clone = node.cloneNode(true); // 2. Imposta come non bloccante (caricamento differito) // Questo permette alle icone di caricarsi SENZA bloccare il sito clone.media = 'print'; clone.onload = function() { this.media = 'all'; }; // 3. SOSTITUZIONE FISICA // Inserisci il clone prima dell'originale if (node.parentNode) { node.parentNode.insertBefore(clone, node); // Rimuovi l'originale (questo cancella la richiesta bloccante pendente) node.parentNode.removeChild(node); console.log("🔄 CSS Swapped (Render Block fix):", node.href); } } } } // A. Azione Retroattiva (sui link già presenti) var links = Array.from(document.getElementsByTagName('link')); links.forEach(swapCSS); // B. Observer per nuovi link const obs = new MutationObserver((mutations) => { mutations.forEach((m) => m.addedNodes.forEach((n) => { if (n.nodeType === 1) { swapCSS(n); if (n.hasChildNodes()) { var subLinks = n.getElementsByTagName('link'); for (var i=0; i