From 11f18e369726fb5db5a861b09a911ecabd0ea9fc Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Sat, 13 Jul 2019 15:06:09 +0200 Subject: [PATCH] Download page: Improved performance for Chromium-based browsers (#1907) This significantly reduces the time it takes to highlight the code of Prism on the download page in Chromium-based browsers. It does this by creating a new DOM node and highlighting the code in this detached node which seemingly helps Chromium to optimize its layout recalculations. --- scripts/download.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/download.js b/scripts/download.js index 7be6834b74..b6ed649cf7 100644 --- a/scripts/download.js +++ b/scripts/download.js @@ -552,9 +552,15 @@ function generateCode(){ var fileName = 'prism.' + type; var codeElement = $('#download-' + type + ' code'); + var pre = codeElement.parentElement; - codeElement.textContent = text; - Prism.highlightElement(codeElement, true); + var newCode = document.createElement('CODE'); + newCode.className = codeElement.className; + newCode.textContent = text; + + Prism.highlightElement(newCode, true, function () { + pre.replaceChild(newCode, codeElement); + }); $('#download-' + type + ' .download-button').onclick = function () {