Avoid inlining redundant responsive images

This commit is contained in:
2026-05-22 13:20:26 -07:00
parent 2b28ada9d1
commit 3569b11da4
2 changed files with 30 additions and 0 deletions

View File

@@ -103,6 +103,29 @@ test("removes image preload srcsets when the link has no href", async () => {
assert.deepEqual(findExternalAssetRefs(output), []);
});
test("drops responsive image candidates after snapshot src is available", async () => {
const fetched = [];
const inliner = new AssetInliner();
inliner.fetchAsset = async (rawUrl) => {
fetched.push(rawUrl);
return {
bytes: Buffer.from("asset"),
contentType: "image/jpeg"
};
};
const output = await inliner.inlineHtml(`
<picture>
<source srcset="/small.webp 640w, /large.webp 1280w" type="image/webp">
<img src="/selected.jpg" srcset="/small.jpg 640w, /large.jpg 1280w">
</picture>
`, "https://example.com/article");
assert.deepEqual(fetched, ["https://example.com/selected.jpg"]);
assert.doesNotMatch(output, /srcset=/);
assert.deepEqual(findExternalAssetRefs(output), []);
});
test("asset inliner skips URLs blocked by the filter hook", async () => {
const blocked = [];
const inliner = new AssetInliner({