From 6ac3f0c84d8d1941772995f329fe29f7ae5ea426 Mon Sep 17 00:00:00 2001 From: Bonnie Zheng Date: Mon, 15 Apr 2024 12:24:24 -0700 Subject: [PATCH] TDW-1646 move admiral to dependencies --- scripts/delayed.js | 24 ------------------------ scripts/dependencies.js | 20 ++++++++++++++++++++ scripts/scripts.js | 10 ++++++++++ 3 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 scripts/dependencies.js diff --git a/scripts/delayed.js b/scripts/delayed.js index b724abbd..65ee7fa9 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -755,27 +755,3 @@ const hasWeFevo = document.querySelector('a.we-fevo-btn'); if (hasWeFevo) { injectWeFevoScript(); } - -/** - * Loads Admiral script - */ -function loadAdmiral() { - const fetchScript = async () => { - try { - const response = await fetch( - 'https://orchestrator-config-uat.pgatour.com/revops/admirial', - ); - const content = await response.text(); - const script = document.createElement('script'); - script.type = 'text/javascript'; - script.innerHTML = content; - script.id = 'admiral'; - document.head.appendChild(script); - } catch (error) { - throw new Error('Error loading Admiral script: ', error); - } - }; - fetchScript(); -} - -loadAdmiral(); diff --git a/scripts/dependencies.js b/scripts/dependencies.js new file mode 100644 index 00000000..c1020103 --- /dev/null +++ b/scripts/dependencies.js @@ -0,0 +1,20 @@ +/** + * Loads Admiral script + */ +async function loadAdmiral() { + try { + const response = await fetch( + 'https://orchestrator-config-uat.pgatour.com/revops/admirial', + ); + const content = await response.text(); + const script = document.createElement('script'); + script.type = 'text/javascript'; + script.innerHTML = content; + script.id = 'admiral'; + document.head.appendChild(script); + } catch (error) { + throw new Error('Error loading Admiral script: ', error); + } +} + +loadAdmiral(); diff --git a/scripts/scripts.js b/scripts/scripts.js index 0d58e1de..7603af43 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -1052,6 +1052,14 @@ async function loadEager(doc) { } } +/** + * Loads everything that required HTML to be in place. + */ +function loadDependencies() { + // eslint-disable-next-line import/no-cycle + import('./dependencies.js'); +} + /** * loads everything that doesn't need to be delayed. */ @@ -1059,6 +1067,8 @@ async function loadLazy(doc) { const main = doc.querySelector('main'); await loadBlocks(main); + loadDependencies(); + const { hash } = window.location; const element = hash ? main.querySelector(hash) : false; if (hash && element) element.scrollIntoView();