
Bên cạnh đó, hiệu ứng chuyển opacity nhẹ khi ảnh load xong mang lại trải nghiệm hiển thị mượt mà, tránh hiện tượng ảnh xuất hiện đột ngột. Tổng thể, đây là giải pháp đơn giản nhưng hiệu quả để nâng cao tốc độ website, tối ưu SEO và cải thiện trải nghiệm người dùng.
TĂNG TỐC ĐỘ LOAD WEBSITE BLOGSPOT
Chèn đoạn Code sau vào trước thẻ đóng </body>
<script>
document.addEventListener("DOMContentLoaded", function () {
const images = document.querySelectorAll("img");
images.forEach(img => {
// Bỏ lazy cho ảnh quan trọng
if (
img.closest("header") ||
img.classList.contains("no-lazy") ||
img.getAttribute("loading") === "eager"
) {
img.setAttribute("loading", "eager");
return;
}
// Lazy load native
img.setAttribute("loading", "lazy");
// Decode async
img.setAttribute("decoding", "async");
// Fade mượt hơn (không nháy)
img.style.transition = "opacity 0.4s ease";
if (!img.complete) {
img.style.opacity = "0.2";
img.addEventListener("load", () => {
img.style.opacity = "1";
});
}
});
});
</script>
Lưu lại và kiểm tra ngay nhé!
Tham khảo thêm phương án khác: TẠI ĐÂY
