Don't use `getAttribute` if we don't need to

Don't use `getAttribute` if we don't need to
diff --git a/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6 b/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6
index 0700c49..e390a9d 100644
--- a/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6
+++ b/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6
@@ -12,17 +12,11 @@ function hide(image) {
   image.classList.add("d-lazyload");
   image.classList.add("d-lazyload-hidden");
 
-  imageSources.set(image, {
-    src: image.getAttribute("src"),
-    srcSet: image.getAttribute("srcset")
-  });
+  imageSources.set(image, { src: image.src, srcset: image.srcset });
   image.removeAttribute("srcset");
 
-  image.setAttribute(
-    "src",
-    image.getAttribute("data-small-upload") || LOADING_DATA
-  );
-  image.removeAttribute("data-small-upload");
+  image.src = image.dataset.smallUpload || LOADING_DATA;
+  delete image.dataset.smallUpload;
 }
 
 // Restore an image when onscreen
@@ -42,9 +36,7 @@ function show(image) {
     };
 
     copyImg.src = sources.src;
-    if (sources.srcSet) {
-      copyImg.srcset = sources.srcSet;
-    }
+    copyImg.srcset = sources.srcset || copyImg.srcset;
 
     copyImg.style.position = "absolute";
     copyImg.style.top = 0;

GitHub
sha: a2ae6750

1 Like