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,nameandmime; -
width,heightandbytes; -
altandcaption, per language; -
author,copyrightandsource; -
focusandfocus_by; -
versionandavailable; -
webp,avifandog. -
webpandavifgive per width thewidth,height,nameandbytes. AVIF is only there where it is at least 10% smaller than the WebP.avifanswers 404 while Serve AVIF is off. -
ogis the image for sharing. It is at most 1200 px, in the format of the original, so every platform shows it. -
focusis{x, y}in percent from the top left, ornullfor the middle. Use it asobject-position, withobject-fit: cover.focus_byis{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>/originalanswers 404. That is also true for an upload in a draft. Serve 404 too, until the file is inGET files. After that, fetch it at its first request. So nothing leaks from a draft. versionchanges with the content. Put it, or a hash of the bytes, in the address you serve. Examples are/file/…/name.<hash>.webpand?v=<version>. Then cache files for a year, withCache-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_versionin 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_onlymeans: only serve the WebP files, where they exist.
Also called: assets, image CDN, responsive images, srcset, WebP, AVIF, focal point, web fonts.
Last changed