Run dom manips before adding to tree so we don't duplicate resource requests

This commit is contained in:
Hamcha 2020-06-21 20:51:15 +02:00
parent 404b74321b
commit b498669487
Signed by: hamcha
GPG key ID: 41467804B19A3315

View file

@ -53,15 +53,20 @@ async function loadPage(page: string, elem: HTMLElement) {
await nextAnimationFrame();
// Set as HTML content and run HTML manipulations on it
elem.innerHTML = html;
const div = document.createElement("div");
div.className = elem.className;
div.innerHTML = html;
console.log(`${page}: processing`);
processHTML(elem, page);
processHTML(div, page);
// Save result to cache
cache.set(key, elem.outerHTML, CURRENT_VERSION).then(() => {
cache.set(key, div.outerHTML, CURRENT_VERSION).then(() => {
console.log(`${page}: saved to cache`);
});
elem.replaceWith(div);
elem = div;
} else {
// Set cached content as HTML
elem.outerHTML = html;