From d3c0f2861bfa5bc04ac217f18e4b80edd4f2025b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 6 Jul 2019 17:23:43 +0200 Subject: [PATCH] Delay initialization of searching, in the viewer, until the first page has rendered When searching occurs for the first time in a document, the `textContent` of all pages will be fetched from the API. If there's a pending search operation when the document loads that will thus lead to a lot of `getTextContent` calls very early on, which may unnecessarily delay rendering of the first page. Generally, in the viewer, a number of non-essential API calls[1] will be deferred until the first page has been rendered, and there's no good reason as far as I can tell to handle searching differently. --- [1] Such as e.g. `getOutline` and `getAttachments`. --- web/base_viewer.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index 45578ac85..471ee0012 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -443,6 +443,10 @@ class BaseViewer { // starts to create the correct size canvas. Wait until one page is // rendered so we don't tie up too many resources early on. onePageRenderedCapability.promise.then(() => { + if (this.findController) { + this.findController.setDocument(pdfDocument); // Enable searching. + } + if (pdfDocument.loadingParams['disableAutoFetch']) { // XXX: Printing is semi-broken with auto fetch disabled. pagesCapability.resolve(); @@ -471,9 +475,6 @@ class BaseViewer { this.eventBus.dispatch('pagesinit', { source: this, }); - if (this.findController) { - this.findController.setDocument(pdfDocument); // Enable searching. - } if (this.defaultRenderingQueue) { this.update(); }