Skip to main content

WASM Loading & Caching

pdfnova uses Google's PDFium engine compiled to WebAssembly via @embedpdf/pdfium.

How It Works

  1. On first PDFDocument.open(), the WASM binary (4.4 MB) is fetched from jsDelivr CDN
  2. With Brotli compression (standard on CDNs), the actual transfer is ~1.5 MB
  3. The binary is cached in IndexedDB — subsequent visits load instantly with zero network cost
  4. The module is initialized and adapted to pdfnova's typed interface

Size Breakdown

ComponentSize
pdfnova JS (lite)~3 KB minified
pdfnova JS (full)~5 KB minified
PDFium WASM (on disk)4.4 MB
PDFium WASM (Brotli transfer)~1.5 MB
PDFium WASM (after IndexedDB cache)0 bytes (cached)

Custom WASM URL

Self-host the WASM binary for air-gapped environments or custom CDN:

const doc = await PDFDocument.open(data, {
wasmUrl: "https://cdn.example.com/pdfium.wasm",
});

Copy the binary from your node_modules:

cp node_modules/@embedpdf/pdfium/dist/pdfium.wasm public/

Clear Cache

If you need to force a re-download (e.g., after updating the WASM version):

import { WasmLoader } from "pdfnova/lite";

await WasmLoader.clearCache();

Preloading

To avoid the loading delay on first PDF open, preload the WASM during app startup:

import { WasmLoader } from "pdfnova/lite";

// Start loading immediately (non-blocking)
WasmLoader.load();

// Later, when the user opens a PDF, it's already loaded
const doc = await PDFDocument.open(file);

Server Configuration

For optimal performance, ensure your server sends the WASM with proper compression:

HeaderValue
Content-Typeapplication/wasm
Content-Encodingbr (Brotli) or gzip
Cache-Controlpublic, max-age=31536000, immutable

Most CDNs (jsDelivr, Cloudflare, CloudFront, Vercel) handle this automatically.