Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions _11ty/img-dim.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ const processImage = async (img, outputPath) => {
if (!fallback) {
return;
}
const avifFallback = await setSrcset(avif, src, "avif");
const [avifFallback, webpFallback] = await Promise.all([
setSrcset(avif, src, "avif"),
setSrcset(webp, src, "webp"),
]);
if (avifFallback) {
avif.setAttribute("type", "image/avif");
picture.appendChild(avif);
}
const webpFallback = await setSrcset(webp, src, "webp");
if (webpFallback) {
webp.setAttribute("type", "image/webp");
picture.appendChild(webp);
Expand Down Expand Up @@ -153,7 +155,11 @@ const dimImages = async (rawContent, outputPath) => {
const images = [...dom.window.document.querySelectorAll("img,amp-img")];

if (images.length > 0) {
await Promise.all(images.map((i) => processImage(i, outputPath)));
const concurrencyLimit = 1;
for (let i = 0; i < images.length; i += concurrencyLimit) {
const chunk = images.slice(i, i + concurrencyLimit);
await Promise.all(chunk.map((img) => processImage(img, outputPath)));
}
content = dom.serialize();
}
}
Expand Down