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
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 is never called for a page that has nothing drawn yet.
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 within a frame of the page's content being painted. To measure the moment the browser has certainly painted it, defer with a nested
requestAnimationFramecall.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.