Pictures, media and fonts from your server
A deck stores pictures, audio, video and fonts as references: media:… for the parts of an opened PowerPoint file, or your own paths (/folio-media/<id>) for what your app stored. Folio turns them into URLs through your resolver. For a big deck, give it resolveSrcs: Folio then asks for many srcs in one call, only for what's on screen, and never floods your server.
resolveSrcs
type MediaPurpose = 'image' | 'media' | 'font' | 'variant';
type SrcBatchResolver = (
ids: string[],
hint?: { purpose: MediaPurpose },
) => Promise<Record<string, string | null | undefined>>;- In: stored srcs, at most 50 per call, all with the same
purpose. - Out: for each id, a URL to load it from, or
nullwhen you don't have it. Return URLs, never the bytes: nodata:URLs with base64 in JSON. A signed URL to your storage or CDN is ideal. - Errors: throw an error with
status(orresponse.status, as axios does). A 503, 429, 502 or 504, or a network error, is retried with exponential backoff and jitter (up to 5 times, at most 30 s apart). Any other error leaves those srcs unresolved for a minute.
It is accepted wherever resolveSrc is:
<SlidesApp deck={deck} measurer={engine} resolveSrcs={resolveSrcs} />
<SlideDeck presentation={pres} measurer={engine} resolveSrcs={resolveSrcs} />
slidesReaderPlugin({ resolveSrcs })
<SlideShow presentation={pres} layout={layout} resolveSrcs={resolveSrcs} />resolveSrc keeps working. When you give both, resolveSrc only answers media: srcs (an opened file's own parts, as blob URLs) and everything else goes through resolveSrcs.
SlideShow takes it too (resolveSrcs on the show, motionUiPlugin({ resolveSrcs }) for the presenter's slide show): one resolver per show, the current slide and two on each side asked for ahead, the presenter view and audience windows loading their pictures through it. Audio and video in a show go through resolveSrcs too (purpose 'media'), so a URL that arrives after the slide shows starts its player then.
What Folio does with it
- Lazy. Only slides on screen are drawn (thumbnail rows in view, the sorter's cells in view, the current slide), plus the current slide and two on each side resolved ahead, so paging is instant.
- Batched. Every canvas asks for all the pictures of its slide before drawing them, and asks made in the same frame (16 ms) go out as one call. Scrolling fast makes one call per frame, not one per picture.
- Cached. Each src is asked once. A URL is reused for 10 minutes, then asked for again in the background while the old one keeps working (signed URLs that expire after 15 minutes are fine). A
nullis remembered for a minute. - Bounded. At most 2 batch calls in flight and 6 picture downloads at once. A download that hasn't started when its slide scrolls away is dropped; the slide asks again when it's back.
- Windowed. Moving to another slide drops the srcs queued for the previous window that weren't sent yet (never one a canvas is waiting for).
Fonts
The font loader batches too. Give loadFamilies instead of loadFamily:
type LoadFamilies = (families: string[]) =>
Promise<Record<string, FontFaceInput[] | null | undefined>>;
createFontLoader({ engine, loadFamilies });
readerFonts({ engine, loadFamily, loadFamilies });ensure asks for every family a document uses in one call, then for the stand-ins of the missing ones in one more. Return every face (weights and styles) of each family in that answer; don't make Folio ask per variant.
A variable font file draws every weight its wght axis spans, whatever weight you label its row with. Folio also pins axes such as optical size (opsz) to the values of the font's own named instances, as Office and LibreOffice draw them (DM Sans' default is its heavier 9 pt cut).
A family named after one of the font's named instances draws that instance. Decks ask for "Bahnschrift Condensed" or "Bahnschrift SemiBold SemiCondensed" while the file, embedded or loaded, is variable Bahnschrift. Registered under that name, the face is pinned to the instance's width (wdth 75) and, when the name gives one, its weight.
Recommended backend
- One endpoint:
POST /media/resolvewith{ ids, purpose }returning{ [id]: url | null }, checking access once for the whole list. - Signed URLs straight to storage or a CDN, valid for at least 15 minutes, with
Cache-Control: private, max-age=…and anETag, so the browser reuses downloads across slides and visits. - Serve the files themselves with their real content type, never as base64 in JSON: base64 adds a third to the size, can't be cached by the browser, and has to be decoded on the main thread.
- Let the endpoint answer
429or503withRetry-Afterwhen it's busy; Folio backs off instead of retrying at once.