|
|
@@ -82,9 +82,6 @@ const SingleFileCore = (() => {
|
|
|
if (!this.options.jsEnabled || (this.options.saveRawPage && this.options.removeScripts)) {
|
|
|
this.processor.insertNoscriptContents();
|
|
|
}
|
|
|
- if (this.options.lazyLoadImages) {
|
|
|
- this.processor.lazyLoadImages();
|
|
|
- }
|
|
|
if (this.options.removeFrames) {
|
|
|
this.processor.removeFrames();
|
|
|
}
|
|
|
@@ -145,6 +142,9 @@ const SingleFileCore = (() => {
|
|
|
}
|
|
|
});
|
|
|
await this.pendingPromises;
|
|
|
+ if (this.options.lazyLoadImages) {
|
|
|
+ this.processor.lazyLoadImages();
|
|
|
+ }
|
|
|
if (this.options.removeUnusedCSSRules) {
|
|
|
this.processor.removeUnusedCSSRules();
|
|
|
}
|
|
|
@@ -281,19 +281,19 @@ const SingleFileCore = (() => {
|
|
|
|
|
|
lazyLoadImages() {
|
|
|
this.doc.querySelectorAll("img[data-src]").forEach(imgElement => {
|
|
|
- if (imgElement.dataset.src && imgElement.src != imgElement.dataset.src) {
|
|
|
+ if (imgElement.dataset.src && imgElement.dataset.src.startsWith(DATA_URI_PREFIX) && imgElement.src != imgElement.dataset.src) {
|
|
|
imgElement.src = imgElement.dataset.src;
|
|
|
imgElement.removeAttribute("data-src");
|
|
|
}
|
|
|
});
|
|
|
this.doc.querySelectorAll("img[data-original]").forEach(imgElement => {
|
|
|
- if (imgElement.dataset.original && imgElement.src != imgElement.dataset.original) {
|
|
|
+ if (imgElement.dataset.original && imgElement.dataset.original.startsWith(DATA_URI_PREFIX) && imgElement.src != imgElement.dataset.original) {
|
|
|
imgElement.src = imgElement.dataset.original;
|
|
|
imgElement.removeAttribute("data-original");
|
|
|
}
|
|
|
});
|
|
|
this.doc.querySelectorAll("[data-bg]").forEach(element => {
|
|
|
- if (element.dataset.bg && !element.style.backgroundImage.includes(element.dataset.bg)) {
|
|
|
+ if (element.dataset.bg && element.dataset.bg.startsWith(DATA_URI_PREFIX) && !element.style.backgroundImage.includes(element.dataset.bg)) {
|
|
|
element.style.backgroundImage = "url(" + element.dataset.bg + ")";
|
|
|
element.removeAttribute("data-bg");
|
|
|
}
|
|
|
@@ -448,14 +448,19 @@ const SingleFileCore = (() => {
|
|
|
}
|
|
|
|
|
|
async pageResources() {
|
|
|
- await Promise.all([
|
|
|
+ const resourcePromises = [
|
|
|
DomProcessorHelper.processAttribute(this.doc.querySelectorAll("link[href][rel*=\"icon\"]"), "href", this.baseURI),
|
|
|
DomProcessorHelper.processAttribute(this.doc.querySelectorAll("img[src], input[src][type=image], object[type=\"image/svg+xml\"], object[type=\"image/svg-xml\"], embed[src*=\".svg\"]"), "src", this.baseURI),
|
|
|
DomProcessorHelper.processAttribute(this.doc.querySelectorAll("video[poster]"), "poster", this.baseURI),
|
|
|
DomProcessorHelper.processAttribute(this.doc.querySelectorAll("*[background]"), "background", this.baseURI),
|
|
|
DomProcessorHelper.processAttribute(this.doc.querySelectorAll("image, use"), "xlink:href", this.baseURI),
|
|
|
DomProcessorHelper.processSrcset(this.doc.querySelectorAll("[srcset]"), this.baseURI, this.dom)
|
|
|
- ]);
|
|
|
+ ];
|
|
|
+ if (this.options.lazyLoadImages) {
|
|
|
+ resourcePromises.push(this.doc.querySelectorAll("img[data-src], img[data-original], [data-bg]"));
|
|
|
+ resourcePromises.push(DomProcessorHelper.processSrcset(this.doc.querySelectorAll("[data-srcset]"), this.baseURI, this.dom));
|
|
|
+ }
|
|
|
+ await resourcePromises;
|
|
|
}
|
|
|
|
|
|
async inlineStylesheets(initialization) {
|