From 46638bc01b4a52cd314c7d06ac110361d95b852e Mon Sep 17 00:00:00 2001 From: Jan Vojt Date: Tue, 27 Oct 2020 10:37:45 +0100 Subject: [PATCH] Fix unnecessary load of images when parsing the document text for search function. The issue was, that when searching, new element with all the HTML content was created. This caused loading of all images in the background. However, in the end, these images are stripped from search result anyway, so there is no point in loading them. In cases where images were included in HTML files in a different directory from search.html, this behaviour was even causing 404 errors because of wrong relative URLs. This commit fixes the issue by creating virtual document and using that as the owner document of temporary meta-element used for searching and parsing purposes. The virtual owner document causes browser to not load the images. --- sphinx/themes/basic/static/searchtools.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index 970d0d975..261ecaa92 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -59,10 +59,10 @@ var Search = { _pulse_status : -1, htmlToText : function(htmlString) { - var htmlElement = document.createElement('span'); - htmlElement.innerHTML = htmlString; - $(htmlElement).find('.headerlink').remove(); - docContent = $(htmlElement).find('[role=main]')[0]; + var virtualDocument = document.implementation.createHTMLDocument('virtual'); + var htmlElement = $(htmlString, virtualDocument); + htmlElement.find('.headerlink').remove(); + docContent = htmlElement.find('[role=main]')[0]; if(docContent === undefined) { console.warn("Content block not found. Sphinx search tries to obtain it " + "via '[role=main]'. Could you check your theme or template.");