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();