Vấn đề ở đây Lỗi Cache IMG có thể là do trình duyệt đang cache ảnh cũ, vì khi document.getElementById(‘image’).src được cập nhật với cùng một URL, trình duyệt có thể không tải lại ảnh mới vì nó đã cache URL này. Để giải quyết vấn đề này, bạn có thể thêm một tham số ngẫu nhiên vào cuối URL của ảnh, làm cho URL luôn là duy nhất và buộc trình duyệt tải lại ảnh.
Bạn có thể sửa lại đoạn JavaScript để thêm một chuỗi ngẫu nhiên vào cuối URL:
new Date().getTime(): Tạo một giá trị ngẫu nhiên bằng cách lấy thời gian hiện tại dưới dạng số milliseconds kể từ 1970. Điều này sẽ làm cho URL của ảnh mỗi lần khác nhau (ví dụ: processed_image.jpg?t=1632974938743), và trình duyệt sẽ buộc phải tải lại ảnh thay vì lấy từ cache.
Với cách này, trình duyệt sẽ luôn tải lại ảnh mới ngay cả khi URL của ảnh gốc không thay đổi.
Leave A Comment