Remove image preload refs without href

This commit is contained in:
2026-05-16 23:03:49 -07:00
parent 0ef0360fde
commit 2b28ada9d1
2 changed files with 31 additions and 3 deletions

View File

@@ -206,11 +206,11 @@ export class AssetInliner {
const rel = getAttribute(tag, "rel") || "";
const href = getAttribute(tag, "href");
const asValue = getAttribute(tag, "as") || "";
if (!href) {
return tag;
}
if (/\bstylesheet\b/i.test(rel)) {
if (!href) {
return tag;
}
const absolute = resolveUrl(href, baseUrl);
if (!absolute || absolute.startsWith("data:")) {
return "";
@@ -237,12 +237,19 @@ export class AssetInliner {
}
let output = tag;
if (/\bpreload\b/i.test(rel) && /^image$/i.test(asValue)) {
if (!href) {
return "";
}
const imageSrcset = getAttribute(output, "imagesrcset");
if (imageSrcset) {
output = setAttribute(output, "imagesrcset", await this.inlineSrcset(imageSrcset, baseUrl));
}
}
if (!href) {
return tag;
}
const dataUri = await this.toDataUri(href, baseUrl, linkResourceType(asValue));
if (!dataUri) {
return "";