Skip to content

Commit

Permalink
TDW-1646 move admiral to dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonnie Zheng committed Apr 15, 2024
1 parent 23d6d8b commit 6ac3f0c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
24 changes: 0 additions & 24 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
20 changes: 20 additions & 0 deletions scripts/dependencies.js
Original file line number Diff line number Diff line change
@@ -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();
10 changes: 10 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,13 +1052,23 @@ 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.
*/
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();
Expand Down

0 comments on commit 6ac3f0c

Please sign in to comment.