From cd6e683883031ed9529081477efad552263f331a Mon Sep 17 00:00:00 2001 From: Shogun Date: Fri, 18 Mar 2022 17:58:55 +0100 Subject: [PATCH] doc: defer script loading --- doc/api_assets/api.js | 18 ++++++++++-------- doc/template.html | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/doc/api_assets/api.js b/doc/api_assets/api.js index 546722cd908ce7..3e7cf017f602ee 100644 --- a/doc/api_assets/api.js +++ b/doc/api_assets/api.js @@ -118,14 +118,16 @@ function setupStickyHeaders() { ).observe(header); } -// Check if we have JavaScript support -document.querySelector(':root').classList.add('has-js'); +document.addEventListener('DOMContentLoaded', function() { + // Check if we have JavaScript support + document.querySelector(':root').classList.add('has-js'); -// Restore user mode preferences -setupTheme(); + // Restore user mode preferences + setupTheme(); -// Handle pickers with click/taps rather than hovers -setupPickers(); + // Handle pickers with click/taps rather than hovers + setupPickers(); -// Track when the header is in sticky position -setupStickyHeaders(); + // Track when the header is in sticky position + setupStickyHeaders(); +}, { once: true }); diff --git a/doc/template.html b/doc/template.html index a65e51d9d46bae..94e2937dcaf897 100644 --- a/doc/template.html +++ b/doc/template.html @@ -74,6 +74,6 @@

Node.js __VERSION__ documentation

- +