Eleventy --incremental builds: global data changes not propagating to dependent templates
0 reputation · 27 Sept 2024, 01:43 UTC
0 reputation · 27 Sept 2024, 01:43 UTC
I am configuring an Eleventy (11ty) project to use the --incremental flag so that only changed templates are rebuilt, keeping build times low on a site with a few thousand pages. The goal is for edits to a global data file (for example, a file under _data) to trigger regeneration of every template that consumes that data, without forcing a full rebuild of the whole site.
The constraint I am unsure about is how Eleventy's incremental mode tracks dependencies between global data files and templates. My understanding is that the cache in the project's cache directory records file modification state, but it is unclear whether a change to a shared data file reliably marks all downstream templates as dirty, or only templates with an explicit dependency edge. I am also unsure how this interacts with the data cascade, where data can come from directory data files and front matter layered together.
Assume Eleventy v2/v3 behavior; please note the version your answer applies to.
--incremental guarantee that changing a global data file rebuilds every page that references it, or are there dependency shapes it misses?Eleventy's --incremental mode (v2/v3 era) builds a dependency graph between templates and data files. A change to a file under _data normally marks every template that statically references it as dirty, so those pages regenerate without a full rebuild. But the guarantee only covers statically detectable usage. There is no configuration flag to force all templates dirty, and in CI a full build is the safer default unless you deliberately persist the cache.
Confirmed behavior: Eleventy tracks which templates consume which data files and rebuilds the consuming templates when a data file changes. The data cascade (directory data files, front matter, layout chaining) is respected, but only where Eleventy can statically associate the data source with the template.
The likely explanation for missed rebuilds is one of these dependency shapes:
_data/site.js may not dirty anything.There is no documented option to declare "everything depends on this file." The practical patterns are:
_data values directly in templates rather than loading files inside filters or shortcodes.Persisting the cache directory across CI runs is fragile. CI jobs typically start from a fresh clone, so all file timestamps change, which can make the incremental cache unreliable and produce stale or skipped output. A full build in CI is the recommended default. If you need incremental builds in CI, you must preserve the cache folder between runs and ensure the filesystem reports accurate modification times — otherwise don't trust it.
Run a minimal reproduction against your installed version:
# add _data/meta.json, reference it in one page, then:
npx eleventy --incremental
# edit _data/meta.json
npx eleventy --incremental
# confirm the consuming page's output changedAlso test any dynamic pattern (a filter that reads a file) by editing the underlying file and checking whether the page regenerates. If it doesn't, require full builds for those edits. In CI, diff a full build against an incremental build on a fresh clone — matching page counts and content is the bar for trusting cache persistence.
Note: this reflects v2/v3-era behavior; dependency-tracking internals have evolved across releases, so confirm against the version pinned in your project.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.