Add These scripts to animation heavy web pages. This frees up extra memory after you navigate away from them.
function cleanupImages() {
document.querySelectorAll("img.animated").forEach(img => {
// Remove the image from the DOM
img.parentNode.removeChild(img);
// Optionally null the src to help garbage collection
img.src = "";
});
}
function cleanupVideos() {
const videos = document.querySelectorAll("video");
console.log(`Cleaning up ${videos.length} videos`);
videos.forEach(video => {
console.log("Before:", video.currentSrc);
video.pause();
video.removeAttribute("src");
video.load();
console.log("After:", video.currentSrc);
});
}