Closed SidVal closed 5 years ago
Para ciertas imágenes quiero poner algún simple script que me ayude a optimizar las cargas de imágenes.
Después de leer: Five Techniques to Lazy Load Images for Website Performance, me quedo con esta idea muy simple, que tengo que probar: Simple Image Lazy Load and Fade
img { opacity: 1; transition: opacity 0.3s; } img[data-src] { opacity: 0; }
[].forEach.call(document.querySelectorAll('img[data-src]'), function(img) { img.setAttribute('src', img.getAttribute('data-src')); img.onload = function() { img.removeAttribute('data-src'); }; });
<img data-src="/path/to/image.jpg" alt="">
Probando aquí:
Para ciertas imágenes quiero poner algún simple script que me ayude a optimizar las cargas de imágenes.
Después de leer: Five Techniques to Lazy Load Images for Website Performance, me quedo con esta idea muy simple, que tengo que probar: Simple Image Lazy Load and Fade
<img data-src="/path/to/image.jpg" alt="">