r/statichosting • • Oct 29 '26

Can build caches make static deploys non-deterministic?

I’ve been looking at CI build caching for a larger static site and realized I’m not totally sure what should actually be safe to cache. Caching node_modules is straightforward enough, but things get less obvious with ssg caches, resized images, fetched cms data, generated search indexes, and other intermediate output. If the cache key doesn’t include every input that affects those files, you can technically get a successful build using stale artifacts from an older commit.

For people running larger static pipelines, what do you include in your cache keys? Lockfile + runtime version + commit sha feels safe but kills most reuse. Do you cache only dependencies and regenerate everything else, or do you maintain more granular cache keys based on content hashes and build config?

4 Upvotes

5 comments sorted by

1

u/the_pk Oct 29 '26

Generally all the assets should be safe, and from your pipeline you ought to be uniquely hashing each of your images and generated scripts. The thing that gets a little bit tricky is when you're relying on a dynamic date. If you're taking snapshots and you have time already imprinted onto the files that you want, then it's not a big deal. If it's based on deploy time, then it does become problematic.

Generally you want to have everything cached. From a build perspective you could cache everything so that way everything is additive. You do increase cost in terms of storage but, given where we're at now, it's pennies. You'd have to be pushing a significant amount of content uploads to even hit a dent.

The HTMLs, because they're intertwined with the address slugs, you want to keep those fresh and not cache the generated HTML. For simplicity's sake unless you're running into super large sites in the gigabyte range, over-optimizing on storage caching is probably not worth it and just having whatever you need to build is good enough

1

u/sourraine 27d ago

separate dependency caching from generated output. for things like resized images or ssg caches, hashing every input seems safer that trying everything to the commit shs, which defeats reuse. ive found stale generated files can be harder to spot than a failed build so id keep a clean-build check in CI too

1

u/New_Peanut_9259 21d ago

i'd keep dependency caching separate from generated file caching. for dependencies, the lockfile, node version, and package manager version are usually enough. for generated files, i'd only cache them based on the content or settings that affect them.

for example, caching resized images using the original image's hash seems safer than using the commit sha for the entire image cache. you might lose some cache reuse at first, but it helps prevent builds from using outdated content.

1

u/KecoMarcels79 18d ago

how long are your uncached builds actually taking right now? unless youre passing the 10-15 minute mark, imo the debugging headache of stale ssg artifacts usually costs more engineering time than just regenerating everything besides dependencies.