diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 01a606e..8cc6f22 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -40,9 +40,11 @@ const config: Config = { // Self-hosted, cookieless Umami analytics. GitHub Pages cannot reverse-proxy the // script under this origin the way the nginx-served apps do, so it loads directly. // data-domains keeps local dev and the github.io mirror out of the stats. + // static/stats-loader.js adds the tracker only after the page has loaded, so a slow or + // hanging Umami can't hold up the page's load event. scripts: [ { - src: 'https://analytics.codeuctivity.cloud/script.js', + src: '/stats-loader.js', defer: true, 'data-website-id': 'dc19b213-947c-477b-8eb5-4a5816542c18', 'data-domains': 'codeuctivity.cloud', diff --git a/static/stats-loader.js b/static/stats-loader.js new file mode 100644 index 0000000..80b9097 --- /dev/null +++ b/static/stats-loader.js @@ -0,0 +1,16 @@ +// Adds the Umami tracker only after the page has finished loading. A script added before +// `load` holds the load event (and the tab spinner) until it arrives, so when Umami hung +// on 2026-11-14 pages never finished loading. +(() => { + const config = document.currentScript?.dataset; + if (!config?.websiteId) return; + const inject = () => { + const script = document.createElement('script'); + script.src = 'https://analytics.codeuctivity.cloud/script.js'; + script.dataset.websiteId = config.websiteId; + if (config.domains) script.dataset.domains = config.domains; + document.head.appendChild(script); + }; + if (document.readyState === 'complete') inject(); + else window.addEventListener('load', inject, {once: true}); +})();