light-server: convert in the browser

examples/light-server — the server never converts a document to BDF. It serves the documents as they are and a thumbnail image of each, and the browser converts and renders.

cd examples/light-server
node web/build.mjs     # builds web/main.js, web/lib/ (workers + wasm converters), web/fonts/
go run .
open http://127.0.0.1:8081/

What the server does

main.go walks a directory of documents (-dir, ../sample-files by default) and, for each one that has no cached thumbnail yet, converts its first page (all a thumbnail shows: Pages: converter.PageList(1)) in memory with converter.ConvertFile and draws a 320px thumbnail with thumbnail.Make — then throws the converted BDF away. Only the PNG is kept, under -thumbs. The server holds no BDF, ever; it doesn't even know if a file converts a second time the same way. It serves:

What the browser does

web/main.ts reads ?file=, fetches the bytes from /files/, and converts them with the same wasm converter modules the demo site uses (examples/common/convert.ts's ConverterClient, loaded from web/lib/bdf-*.wasm), then opens the result in MiniViewer. The sequence itself is nothing new — the same sniff → convert → open that examples/viewer/main.ts uses, pared down here to one file with no page-turning, cell selection, or streaming PDF pages.

web/build.mjs builds this front end by calling into examples/common/build.mjs — the same helper the demo site is built with — for the rendering worker, the converter worker, the wasm modules (every one but the preview-only module, which this server never needs), and the fonts the Office converters lay text out with.

Why this shape

See Why BDF: the converters build as WebAssembly precisely so a server can be this thin. The cost lands on the browser instead — a wasm module to fetch (7–27 MB depending on the format, gzipped and cached after the first document of that kind) and a moment of local conversion on every open, not just the first. That's the right trade for documents that are made in large numbers but seldom opened. Records kept for an audit are the typical case: every transaction, report or signed form is filed as it is made, yet only the few an auditor asks for are ever looked at. Converting them all ahead of time would spend the server's time and storage on documents nobody opens; here the server only draws a thumbnail as each one comes in, and a document is converted once someone opens it, in their own browser. It also suits a server with no spare capacity to convert at all. For the opposite trade, see preview-server.