Repository navigation
Description
Spun out of the asset compiler design work
(#10,
docs/design/asset_compiler.md, landing with the asset-compiler design PR).
This issue tracks SSG mode (static-site generation) and records why
citry ships nocitry build/ static-export command today, so the
reasoning is not rediscovered when the question comes back.
The two artifacts, and why the compile cache is not a build output
The asset compiler produces an input-side artifact: source dialects
(TS/SCSS/markdown) compiled to base dialects, cached (content-addressed, in
compile_cache) so the live renderer can reach for them. A traditional
build command produces a serving-side artifact: files a dumb file
server (nginx, S3) can host. The asset compiler design deliberately built
only the first.
The bound that no export can escape: citry can never fully pre-generate
its serving surface. Per-render JS/CSS variables scripts (js_data() /
css_data()) are minted during the render that needs them, and which
assets a page needs is decided per render tree at serialize. Any static
export therefore covers class-level JS/CSS and Dependencies files only;
the app stays in the serving loop regardless. An export is only ever an
optimization overlay on citry's own serving path, never a replacement. This
is unlike Django's collectstatic, whose static files are a closed set
known upfront.
Why there is no export command today
- Live server plus CDN needs none. The
asset/<content-hash>and
cache/<class_id>endpoints are fingerprinted and infinitely cacheable;
a CDN in front absorbs everything after first touch. This is the position
the Django ecosystem itself converged on: Whitenoise's docs argue that a
CDN-as-caching-proxy in front of app-served static files beats pushing
files out to S3 and "keeps your deployment simple"
(https://whitenoise.readthedocs.io/en/stable/index.html). - The lazy-warmup precedent already exists in the design.
django-compressor's offline mode ("compression should be done outside of
the request/response loop":manage.py compresswrites the same
artifacts the app would generate lazily, plus a manifest) is exactly what
citry compiledoes, differing only in output medium (cache entries
rather than files). - The direct ancestor never needed one. django-components serves
component assets from cache-backed endpoints
(discussion #670)
and never grew a collectstatic-style export for them.
The escape hatch, when someone actually needs nginx-only hosting
The shape of the answer is one flag, not a build system:
citry compile --export <dir> - after warming, walk the same artifacts and
write them as files (hashed names matching the URLs the emission layer
would emit) plus a small manifest. Ecosystem triggers for wanting this are
minority setups: ops policies that only serve static from nginx, and no-CDN
static hosting (the case Nitro's compressPublicAssets exists for).
Nothing in the asset-compiler design blocks it; nothing requires it yet.
The variables-script bound above applies: exported files cover class-level
assets only.
SSG mode: the real future consumer
If citry grows a static-site mode (render all pages to HTML files), the
asset half is nearly free, because it falls out of the existing emission
machinery:
- Render every page with dependencies emitted as URLs instead of
inline (theas_urlsmode built for fragments already does this). - Dump each referenced URL's cached content to a file at the matching
path, next to the rendered HTML.
No bundler pass is needed (the asset compiler model has no cross-component
bundling; each component's assets are self-contained). The genuinely hard
parts of SSG are everything else: page enumeration, routing, data loading,
and what "all pages" even means for a component engine that has no router.
That needs its own design pass and is out of scope of
#10.
The other adjacents from the same exploration (ESM, minification,
sourcemaps, dev/prod mode) are recorded in
#35.
Scope of this issue
- Design pass for SSG mode: page enumeration and rendering model, the
asset-export walker above, output layout, and how per-render variables
scripts behave in a fully static page (they can be inlined into the
snapshot at render time, which sidesteps the serving bound). - The
citry compile --export <dir>flag can be specified as part of this
design or split out if nginx-only hosting demand arrives first.
References: docs/design/asset_compiler.md sections 3.4 (rejected
alternatives, incl. the export and the Vite delegation) and 9.3 (production
serving); docs/design/dependencies.md (emission, fragments, cache
endpoints); #10.
Activity