0 Σχόλια
0 Μοιράστηκε
66 Views
function supportsWebP() { return new Promise(resolve => { const img = new Image(); img.onload = () => resolve(img.width === 1); img.onerror = () => resolve(false); img.src = "data:image/webp;base64,UklGRhYAAABXRUJQVlA4TAYAAAAvAAAAAA..."; }); } supportsWebP().then(isSupported => { if (!isSupported) { const images = document.querySelectorAll('img[data-fallback]'); images.forEach(img => { img.src = img.dataset.fallback; }); } });