Przeglądaj źródła

delete unused stylesheets

Gildas 7 lat temu
rodzic
commit
46087b69b3
1 zmienionych plików z 6 dodań i 3 usunięć
  1. 6 3
      lib/single-file/single-file-core.js

+ 6 - 3
lib/single-file/single-file-core.js

@@ -790,6 +790,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 					const options = { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled, url: this.options.url, charset: this.charset, compressCSS: this.options.compressCSS };
 					const isLinkTag = element.tagName.toLowerCase() == "link";
 					if (isLinkTag && element.rel.includes("alternate") && element.title) {
+						this.stylesheets.delete(element);
 						element.remove();
 					} else {
 						let stylesheetContent;
@@ -818,15 +819,17 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 								removedRules.forEach(cssRule => stylesheet.children.remove(cssRule));
 							}
 							this.stylesheets.get(element).stylesheet = stylesheet;
+						} else {
+							this.stylesheets.delete(element);
 						}
 					}
 				}));
 		}
 
 		async processStylesheets() {
-			await Promise.all(Array.from(this.stylesheets).map(([, stylesheetInfo]) =>
-				ProcessorHelper.processStylesheet(stylesheetInfo.stylesheet.children, this.baseURI, this.options, this.cssVariables, this.batchRequest)
-			));
+			await Promise.all(Array.from(this.stylesheets).map(([, stylesheetInfo]) => {
+				ProcessorHelper.processStylesheet(stylesheetInfo.stylesheet.children, this.baseURI, this.options, this.cssVariables, this.batchRequest);
+			}));
 		}
 
 		replaceStylesheets() {