Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <body>
- <script>
- (function () {
- var src = "https://www.gravatar.com/avatar/264484e7905f0381280e3d8e83a4c17a?s=32&d=identicon&r=PG";
- var imagesToLoad = 1000;
- function onAllLoaded(img) {
- console.log("All images are loaded");
- console.time("All images are loaded");
- console.time("GC - 1st attempt");
- gc();
- img.src = "https://www.gravatar.com/avatar/1e209e56c63bd72adb0d038377dde562?s=24&d=identicon&r=PG";
- img = null;
- setTimeout(function () {
- console.time("GC - 2nd attempt");
- gc();
- }, 1000);
- }
- function createImg(i) {
- var img = document.createElement("img");
- img.dataset.index = i;
- img.onload = function () {
- console.log("img loaded", this.dataset.index);
- imagesToLoad--;
- if (imagesToLoad === 0) {
- onAllLoaded(this);
- }
- };
- img.onerror = function () {
- console.log("img error", this.dataset.index);
- imagesToLoad--;
- if (imagesToLoad === 0) {
- onAllLoaded(this);
- }
- };
- img.src = src;
- img = null;
- }
- for (var i = 0; i < imagesToLoad; i++) {
- createImg(i);
- }
- })();
- </script>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement