From 7d7cb3f13d323dde3b838b9d820f57b730839444 Mon Sep 17 00:00:00 2001
From: svemagie <869694+svemagie@users.noreply.github.com>
Date: Mon, 11 May 2026 09:09:53 +0200
Subject: [PATCH] perf: hasOgImage filter uses memoized Set lookup; drop
getCallbacks() per-page call
---
eleventy.config.js | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/eleventy.config.js b/eleventy.config.js
index 628bb8c..4d355ad 100644
--- a/eleventy.config.js
+++ b/eleventy.config.js
@@ -404,15 +404,11 @@ export default function (eleventyConfig) {
// Performance: skip PostHTML parsing for pages without tags.
// Both registered PostHTML plugins (remote-image-marker, eleventy-img) only
// target elements — no point parsing+serializing HTML without them.
- // Overrides the default @11ty/eleventy/html-transformer transform (same name
- // overwrites via addTransform) with a pre-check that avoids the full PostHTML
- // parse/serialize cycle (~3ms/page) for image-free pages.
+ // No URL transform callbacks are registered by any plugin, so the getCallbacks()
+ // check is omitted — it costs ~1ms × 639 pages for a result that is always false.
eleventyConfig.addTransform("@11ty/eleventy/html-transformer", async function(content) {
if (typeof this.outputPath === "string" && this.outputPath.endsWith(".html") && !content.includes(", , etc.)
- // we must still run the full pipeline even without images.
- const hasUrlCallbacks = eleventyConfig.htmlTransformer.getCallbacks("html", this).length > 0;
- if (!hasUrlCallbacks) return content;
+ return content;
}
return eleventyConfig.htmlTransformer.transformContent(this.outputPath, content, this);
});
@@ -1018,9 +1014,10 @@ export default function (eleventyConfig) {
});
// Check if a generated OG image exists for this slug
+ // Delegates to the memoized hasOgImage() above (directory listed once per build → Set lookup)
eleventyConfig.addFilter("hasOgImage", (slug) => {
if (!slug) return false;
- return existsSync(resolve(OG_CACHE_DIR, `${slug}.png`));
+ return hasOgImage(slug);
});
// Inline file contents (for critical CSS inlining)