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.
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);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 operation | First-open behavior |
|---|---|
| Viewer JavaScript and core runtime | Required when the first document opens |
| Optional format dispatcher | May be imported early and memoized |
| Optional family Wasm | Load only after content detection selects that family |
| Pages, slides, sheets, and thumbnails | Materialize or render on demand |
| Document-wide search and all-object queries | Start only when the product needs complete-document results |
| Host fonts | Provide 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.
A single fastest-file number is not a product guarantee. Compare the same artifact, environment, cache state, and completion boundary.