Skip to content

Commit

Permalink
Download page: Improved performance for Chromium-based browsers (#1907)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RunDevelopment authored Jul 13, 2019
1 parent 7bd0832 commit 11f18e3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 11f18e3

Please sign in to comment.