Performance optimization

Configure first-open module loading, preserve on-demand work, reuse the Viewer, and measure browser-local performance reproducibly.

Warm the configured format dispatcher

Set viewer.config.engine.formatPack before the first open(). Create and memoize the dynamic-import promise when the application knows optional formats are allowed; creating the promise starts the small JavaScript dispatcher download without waiting for the first document.

ts
import '@docviewkit/viewer';

const formatPack = import('@docviewkit/viewer/extended-formats')
  .then(({ extendedFormatPack }) => extendedFormatPack);

const viewer = document.querySelector('docviewkit-viewer');
viewer.config = {
  engine: {
    formatPack: () => formatPack
  }
};

await viewer.open(file);
Dispatcher warm-up is selective

Importing extended-formats does not fetch every Wasm binary. Bounded content detection selects one matching ODF, PDF/iWork, legacy Office/WPS, or XPS module. If the product accepts only WPS or XPS, use the dedicated wps-formats or xps-formats subpath.

Keep on-demand work out of startup

Resource or operationFirst-open behavior
Viewer JavaScript and core runtimeRequired when the first document opens
Optional format dispatcherMay be imported early and memoized
Optional family WasmLoad only after content detection selects that family
Pages, slides, sheets, and thumbnailsMaterialize or render on demand
Document-wide search and all-object queriesStart only when the product needs complete-document results
Host fontsProvide common static faces or a bounded lazy provider; do not fetch the full catalog first
  • Serve versioned Worker, Wasm, codec, and font assets with normal HTTP caching from the same controlled deployment as the Viewer.
  • Keep one Viewer instance across documents and call close() between them. destroy() also releases the reusable Engine and is intended for removing the component.
  • Do not preload every optional Wasm binary or render every unit before first paint; that defeats the format and unit lazy-loading boundaries.
  • Keep authorization and document acquisition ahead of open(), but avoid unrelated application initialization on the critical path.

Publish measurements with their environment

A reproducible result records the DocViewKit version, browser and version, operating system, hardware, cold or warm cache, input format and bytes, page or unit count, time to open, time to first visible content, peak memory where available, and emitted diagnostics.

No context-free speed claims

A single fastest-file number is not a product guarantee. Compare the same artifact, environment, cache state, and completion boundary.