Implement lazy loading for Audio and Video
This commit is contained in:
@@ -6,4 +6,30 @@
|
||||
document.querySelector("#header #navigation").classList.toggle("open");
|
||||
});
|
||||
|
||||
{ // Lazily load Media
|
||||
let info = {}
|
||||
new Promise((resolve, reject) => {
|
||||
// Figure out what to load.
|
||||
info.elements = document.querySelectorAll(".block-media > [data-lazyload]");
|
||||
info.stack = Array.from(info.elements);
|
||||
console.debug("Lazily loading " + info.stack.length + " elements...");
|
||||
|
||||
// Begin processing at 1ms intervals.
|
||||
info.cbid = 0;
|
||||
info.cbid = window.setInterval(() => {
|
||||
let el = info.stack.pop();
|
||||
let lazycontent = el.querySelector("noscript");
|
||||
el.innerHTML = lazycontent.innerHTML;
|
||||
|
||||
if (info.stack.length == 0) {
|
||||
window.clearInterval(info.cbid);
|
||||
resolve();
|
||||
}
|
||||
}, 1);
|
||||
}).finally(() => {
|
||||
console.debug("Lazy loading complete.");
|
||||
window.clearInterval(info.cbid);
|
||||
});
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user