Another technical coding post where I go over all the ways I try to OPTIMIZE! the performance of my 11ty blog.
brennan.day/rolling-the-…
#11ty #eleventy #webdev #programming

brennan.dayRolling the Boulder Up: Making Eleventy Build 2.6× FasterIt's been a while since my last technical post, and once again we're here trying to optimize and increase build times of my ever-increasingly bloated little blog.
Back in May, I wrote a post about making my Eleventy build five times faster by fixing an offensive git log implementation. In July, I wrote about cutting my Netlify build time in half by caching API responses, removing a dead Discord webhook, and moving post-deploy work out of the build window.
These fixes made significant improvements, as I rolled the boulder of optimization up the hill of self-created code debt. But since then, I kept writing and coding. Brennan.day continues to grow, with more images, tags, archive pages, templates, and clever features I felt were really, _really_ needed.
As a result, we're back at the bottom of the hill and starting again. My local production build now at twenty seconds and Netlify builds at around two and a half minutes. You must choose to imagine me happy.
Let's begin.
## Measure the Build Flags
It is a mistake to treat "the build" as a monolithic, singular blob. Somehow, over time, my `npm run build` command had become:
"build": "eleventy --incremental && npx pagefind --site _site && node scripts/generate-json-feed.js && node scripts/generate-science-feed.js && node scripts/generate-honeypot.js"
It builds Eleventy, then Pagefind search indexing, and then a few additional scripts I've hacked on. I realize it all adds up:
Stage | Current Times
---|---
Full `npm run build` | 20.67s
Eleventy | 14.83s cold / 12.32s warm
Pagefind | 2.80s
Passthrough copying | 823 files, ~580ms
Let's see what we can do to improve those times!
## Font Awesome Parsing Every HTML Document
To start, I use the official @11ty/font-awesome plugin. It works great. I write:
<i class="fa-solid fa-terminal"></i>
And the plugin turns it into an SVG reference while collecting the symbol into a per-page bundle. The problem is that the plugin's transform uses posthtml to parse and transform _every HTML document_. Not just documents with icons and not just the icon tags. Every page in full! And this is after Eleventy had already rendered it.
There are over seven hundred HTML files that make up this site, and so there is a lot of code being parsed for no reason. I kept the plugin, but disabled the transform:
eleventyConfig.addPlugin(pluginFontAwesome, { transform: false });
eleventyConfig.addPlugin(require("./config/fontawesome-fast.js"));
I then wrote a more narrow custom transform in `config/fontawesome-fast.js`. This uses the plugin's code for icon metadata and SVG generation, but now it only looks for `<i>` elements with Font Awesome classes:
eleventyConfig.addTransform("fontawesomeFast", function(content, outputPath) {
if (!outputPath || !outputPath.endsWith(".html") || typeof content !== "string" || !content.includes("<i")) {
return content;
}
// Replace <i class="fa-solid fa-terminal"></i> with:
// <svg ...><use href="#fas-terminal" xlink:href="#fas-terminal"></use></svg>
// and register the symbol with Eleventy's bundle manager.
});
Beyond this, the script also parses attributes, merges default accessibility attributes, caches icon metadata, caches generated SVG fragments, skips icons inside comments, scripts, and styles, etc.
While this works well for my small site, I would not blindly copy this idea if your site accepts arbitrary HTML from strangers.
## `slugify` Needed a Fast Path, Not Just a Cache
In my first performance post, I memoized[1] `slugify`, but it didn't really help anything, since most calls were unique strings.
This time, I looked at how the slugify library itself was doing expensive transliteration work. Nearly all strings were already regular ASCII, so it was pretty silly to have a Unicode transliteration pipeline for each build. The new filter has a cache _and_ a fast path:
eleventyConfig.addFilter("slugify", (str, opts) => {
str = "" + s