cd $ALMANACK_ROOT
make prod-deploy
This rsyncs the local web root to the production server.
Static Asset Caching
The Caddyfile (assets/system/Caddyfile) serves everything under
/static/* with Cache-Control: max-age=31536000, immutable. This
covers JS, CSS, fonts, the favicon, and anything else that ends up in
the static directory. Browsers will cache these indefinitely and skip
conditional requests entirely — no ETags, no 304s, zero network
round-trips for repeat visitors.
Because the cache is immutable, every reference to a static asset must include a cache-busting parameter. If it doesn’t, browsers will serve stale files forever.
Cache-busting mechanisms
There are two, depending on where the asset is referenced:
Django templates (base.html, etc.) use the {% cdnstatic %}
template tag from almnck.templatetags.cdnstaticfiles for all static
asset references — JS, CSS, fonts, everything. In production this
appends the git HEAD hash (cached once at process start). In
development (DEBUG mode) it uses a timestamp so changes appear without
restarting the dev server.
Article markdown sometimes contains hardcoded <script> tags
pointing to /static/js/ (e.g., figure runtimes, import() calls).
These can’t use Django template tags because the markdown is rendered
by Python-Markdown, not the Django template engine. Instead,
render_markdown() in views.py post-processes the HTML and appends
a per-file content hash (first 12 chars of SHA-1 of the file) to any
src="/static/js/..." attribute. The hash only changes when the file
contents change, so an editorial-only deploy won’t invalidate cached
JS. If articles ever reference other static paths (CSS, fonts, etc.),
the same treatment should be extended in render_markdown().
Why not just use ETags?
ETags and Last-Modified headers provide validation caching: the
browser still makes a conditional request on every page load and gets a
304 Not Modified back. This saves bandwidth but not the round-trip
latency. For a static site with infrequent deploys, the immutable
cache with content-hash busting eliminates those round-trips entirely.