From 0177d4cc20a6dd924fbb51b2b1f9a3b13b8d0969 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 9 Feb 2021 22:41:47 +0100 Subject: [PATCH] doc: optimize HTML rendering Defer rendering sections of docs until they are displayed on the user's screen. PR-URL: https://github.com/nodejs/node/pull/37301 Reviewed-By: Darshan Sen Reviewed-By: James M Snell --- doc/api_assets/style.css | 5 +++++ tools/doc/allhtml.js | 4 ++-- tools/doc/html.js | 14 +++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/api_assets/style.css b/doc/api_assets/style.css index d2e79444a93558..e1538d962e2545 100644 --- a/doc/api_assets/style.css +++ b/doc/api_assets/style.css @@ -372,6 +372,11 @@ dd + dt.pre { #apicontent { padding-top: 1rem; } + +#apicontent section { + content-visibility: auto; + contain-intrinsic-size: 1px 5000px; +} #apicontent .line { width: calc(50% - 1rem); diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js index 93197f812e10c6..fad74e59d5cb2e 100644 --- a/tools/doc/allhtml.js +++ b/tools/doc/allhtml.js @@ -36,8 +36,8 @@ for (const link of toc.match(//g)) { contents += data.slice(0, match.index) .replace(/[\s\S]*?id="toc"[^>]*>\s*<\w+>.*?<\/\w+>\s*(
    \s*)?/, ''); - apicontent += data.slice(match.index + match[0].length) - .replace(/[\s\S]*/, '') + apicontent += '
    ' + data.slice(match.index + match[0].length) + .replace(/[\s\S]*/, '
    ') .replace(/ { return htmlFiles.includes(href) ? '/);