Flipbook image source
The same 48-page book as the pdf.js demo, converted to WebP pages at build time and read without pdf.js: no worker, no parser, and the first page in the server-rendered HTML. Text, search and page announcements come from the manifest.
Arrow keys or Page Up and Page Down turn the page. Plus and minus zoom, 0 resets. Home and End go to the first and last page.
48 pre-rendered pages — the same document as the pdf.js demo, with its text from the manifest: select it, or search for “page 12”.
Measured against the pdf.js demo
Both demos from this site's production server build, each opened once with a cold cache in Chromium, on Lighthouse's mobile network (150 ms round trips, 1.6 Mbps) with the CPU slowed four times. Bytes are what crossed the network, compressed, until the first page was drawn sharp.
| Metric | pdf.js demo | Image source |
|---|---|---|
| JavaScript transferred | 728 KB, the pdf.js worker 377 KB of it | 225 KB |
| All bytes transferred | 855 KB | 401 KB |
| First page on screen | 6.4 s | 1.0 s, server-rendered |
| Largest contentful paint | 1.1 s, the page heading: a canvas is never a candidate | 1.1 s, the first page |
The pdf.js demo cannot draw a page before pdf.js and its worker have arrived and parsed the document. The image source sends the first page in the HTML, then fetches the images on screen at the size they are drawn — 800 pixels wide on a phone, 1600 on a desktop at 2x — and the next spread at low priority.
Set it up
Convert the PDF where you build or upload it, with the converter that ships in the package: npx -p @vigdx/flipbook vigdx-flipbook-images catalog.pdf public/books/catalog. It renders with pdf.js and @napi-rs/canvas, which pdf.js already installs, and writes WebP pages 200, 800, 1600 and 2400 pixels wide, the manifest and the text.
Then provide provideFlipbookImages() in place of provideFlipbook() and give the surface the manifest: src="/books/catalog/manifest.json". The overview has the code.
Choose it for books you publish: brochures, catalogues, magazines. Keep pdf.js for documents your readers bring, or that change too often to convert.
