Nutrient Web SDK

ReferenceOnInitialPageRenderCallback

Type Alias OnInitialPageRenderCallback

This callback is called once for each page, the first time that page renders. It is not called again when the page re-renders after a zoom, a rotation, a viewport resize, or a scroll back into view.

Pages render as the reader approaches them, not once for the whole document up front, and the pages next to the current one are rendered ahead of time, so a page can be reported before it is scrolled into view. Its content has finished rendering either way — the callback waits for the page's content to be drawn and made visible before reporting it.

There is one exception. Once a page's image has been placed, the callback waits for that image to confirm it loaded; if the load fails or does not confirm within a short timeout, the page is reported anyway and a warning is logged. A page reported that way carries nothing to distinguish it from one that painted normally, so a measurement built on this callback can include it. A page whose render fails outright is not reported at all until a later attempt succeeds.

A page is identified by its index, and each index is reported at most once for the lifetime of the viewer instance. A page that takes the place of an already reported index after the document is edited is therefore not reported again.

It is registered at configuration time, before rendering starts, so it also observes the first page render, which is why this is the supported way to measure the time to the first rendered page.

The callback is called when the page first has visible content, which is normally its low-resolution preview, with the sharp detail tiles rendered on top of it afterwards.

In a visible tab the callback runs once the page's content has been drawn and made visible, which is normally within a frame of the browser painting it. To measure the moment the browser has certainly painted it, defer with a nested requestAnimationFrame call.

An exception thrown from this callback is caught and logged as a console warning. It does not interrupt rendering, and later pages are still reported.

For more information, see Configuration#onInitialPageRender.

Type Alias
Type Signature
type OnInitialPageRenderCallback = (info: InitialPageRenderInfo) => void

Example

Measure the time until the first page is visible. The first call reports whichever page renders first, which is not page 0 when the viewer starts on another page.

const startedAt = performance.now();
let reported = false;

NutrientViewer.load({
onInitialPageRender: function({ pageIndex }) {
if (reported) return;

reported = true;
console.log(`page ${pageIndex} rendered after ${performance.now() - startedAt}ms`);
},
// ...
});

Type Declaration

Parameters

The page that rendered for the first time.

Returns

void