Skip to content

Files and images

This page explains how files and images leave Lightbolt, and how a frontend caches them.

The media map

Every answer has media. It maps an address to these fields:

  • id, address, name and mime;

  • width, height and bytes;

  • alt and caption, per language;

  • author, copyright and source;

  • focus and focus_by;

  • version and available;

  • webp, avif and og.

  • webp and avif give per width the width, height, name and bytes. AVIF is only there where it is at least 10% smaller than the WebP. avif answers 404 while Serve AVIF is off.

  • og is the image for sharing. It is at most 1200 px, in the format of the original, so every platform shows it.

  • focus is {x, y} in percent from the top left, or null for the middle. Use it as object-position, with object-fit: cover. focus_by is {sm, lg}, with only the sizes that have a point of their own.

Calls

Call What it gives
GET files Every file that may leave, with version.
GET files/<id> One file.
GET files/<id>/original The bytes. It gives 404 for a file that nothing published points at.
GET files/<id>/<format>/<width> The webp or avif bytes.
GET files/<id>/og The image for sharing.
GET fonts/<file id> A font file. site.fonts.css points at /_fonts/<file id>/.

Caching and addresses

This is what Lightbolt guarantees, and how a frontend can cache without anyone ever emptying a cache.

  • A file only leaves once published content uses it. Before that, GET files/<id>/original answers 404. That is also true for an upload in a draft. Serve 404 too, until the file is in GET files. After that, fetch it at its first request. So nothing leaks from a draft.
  • version changes with the content. Put it, or a hash of the bytes, in the address you serve. Examples are /file/…/name.<hash>.webp and ?v=<version>. Then cache files for a year, with Cache-Control: public, max-age=31536000, immutable.
  • A year is safe, also for the CSS and JS of a theme. After a change, the page points at a new address. So a browser fetches it at once, and the old address is never asked for again. A shorter time only makes browsers fetch files that did not change.
  • Keep pages for a short time, and empty them on a signal. Keep a page briefly, for example with private, max-age=10, must-revalidate. Empty your page cache for that environment when a signal says that something changed. Editors then never need a button to clear the cache.
  • An overview follows its children by children_version in the manifest. So when someone publishes a post, it shows on its overview without the overview being published again.

Good to know

  • An image in a field can also be an address outside the map, such as an old path or https://…. Show it as it is.
  • settings.images.webp_only means: only serve the WebP files, where they exist.

Also called: assets, image CDN, responsive images, srcset, WebP, AVIF, focal point, web fonts.

Last changed