From 65dc1b49337188cc647e9f467e0ff98019ba8ae2 Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Fri, 5 Apr 2024 23:47:43 -0700 Subject: [PATCH 1/9] TDW-2277 moved load ads into scriptjs to decrease load time --- scripts/delayed.js | 72 ----------------------------- scripts/scripts.js | 113 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 96 insertions(+), 89 deletions(-) diff --git a/scripts/delayed.js b/scripts/delayed.js index 65ee7fa9..6c7d8024 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -3,12 +3,9 @@ import { decorateIcons, fetchPlaceholders, sampleRUM, - decorateBlock, - loadBlock, loadScript, getMetadata, fetchGraphQL, - sendAnalyticsPageEvent, } from './scripts.js'; const placeholders = await fetchPlaceholders(); @@ -646,75 +643,6 @@ async function populateStatusBar(statusBar) { populateStatusBar(document.querySelector('header > .status-bar')); -/* setup cookie preferences */ -function getCookie(cookieName) { - const name = `${cookieName}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const split = decodedCookie.split(';'); - // eslint-disable-next-line no-plusplus - for (let i = 0; i < split.length; i++) { - let c = split[i]; - while (c.charAt(0) === ' ') c = c.substring(1); - if (c.indexOf(name) === 0) return c.substring(name.length, c.length); - } - return null; -} - -async function OptanonWrapper() { - const geoInfo = window.Optanon.getGeolocationData(); - Object.keys(geoInfo).forEach((key) => { - const cookieName = `PGAT_${key.charAt(0).toUpperCase() + key.slice(1)}`; - const cookie = getCookie(cookieName); - if (!cookie || cookie !== geoInfo[key]) document.cookie = `${cookieName}=${geoInfo[key]}`; - }); - - const prevOptIn = localStorage.getItem('OptIn_PreviousPermissions'); - if (prevOptIn) { - try { - const settings = JSON.parse(prevOptIn); - if (settings.tempImplied) { - localStorage.removeItem('OptIn_PreviousPermissions'); - } - } catch (e) { - // eslint-disable-next-line no-console - console.error('OptIn_PreviousPermissions parse failed'); - } - } - sendAnalyticsPageEvent(); -} - -const otId = placeholders.onetrustId; -if (otId) { - const cookieScript = loadScript('https://cdn.cookielaw.org/scripttemplates/otSDKStub.js'); - cookieScript.setAttribute('data-domain-script', `${otId}${isProd ? '' : '-test'}`); - cookieScript.setAttribute('data-dlayer-name', 'dataLayer'); - cookieScript.setAttribute('data-nscript', 'beforeInteractive'); - - const gtmId = placeholders.googletagmanagerId; - if (gtmId) { - const GTMScript = document.createElement('script'); - GTMScript.innerHTML = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': - new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], - j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= - 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); - })(window,document,'script','dataLayer','${gtmId}');`; - document.head.append(GTMScript); - - const GTMFrame = document.createElement('no-script'); - GTMFrame.innerHTML = ``; - document.body.prepend(GTMFrame); - } - - window.OptanonWrapper = OptanonWrapper; - - if (document.querySelector('.marketing')) { - const marketingBlock = document.querySelector('.marketing'); - decorateBlock(marketingBlock); - loadBlock(marketingBlock); - } -} - async function loadLiveChat() { const liveChat = getMetadata('live-chat'); if (liveChat && ['yes', 'on', 'true'].includes(liveChat.toLowerCase())) { diff --git a/scripts/scripts.js b/scripts/scripts.js index 0d58e1de..3fedbdb8 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -116,8 +116,8 @@ export function addPublishDependencies(url) { */ export function toClassName(name) { return name && typeof name === 'string' - ? name.toLowerCase().replace(/[^0-9a-z]/gi, '-') - : ''; + ? name.toLowerCase().replace(/[^0-9a-z]/gi, '-') + : ''; } /* @@ -250,15 +250,15 @@ export async function fetchPlaceholders(prefix = 'default') { window.placeholders[`${prefix}-loaded`] = new Promise((resolve, reject) => { try { fetch(`${prefix === 'default' ? '' : prefix}/placeholders.json`) - .then((resp) => resp.json()) - .then((json) => { - const placeholders = {}; - json.data.forEach((placeholder) => { - placeholders[toCamelCase(placeholder.Key)] = placeholder.Text; + .then((resp) => resp.json()) + .then((json) => { + const placeholders = {}; + json.data.forEach((placeholder) => { + placeholders[toCamelCase(placeholder.Key)] = placeholder.Text; + }); + window.placeholders[prefix] = placeholders; + resolve(); }); - window.placeholders[prefix] = placeholders; - resolve(); - }); } catch (e) { // error loading placeholders window.placeholders[prefix] = {}; @@ -403,8 +403,8 @@ export function updateSectionsStatus(main) { */ export function decorateBlocks(main) { main - .querySelectorAll('div.section > div > div') - .forEach((block) => decorateBlock(block)); + .querySelectorAll('div.section > div > div') + .forEach((block) => decorateBlock(block)); } /** @@ -632,13 +632,13 @@ export function decorateButtons(element) { up.classList.add('button-container'); } if (up.childNodes.length === 1 && up.tagName === 'STRONG' - && twoup.childNodes.length === 1 && twoup.tagName === 'P') { + && twoup.childNodes.length === 1 && twoup.tagName === 'P') { a.className = 'button primary'; twoup.classList.add('button-container'); up.outerHTML = a.outerHTML; } if (up.childNodes.length === 1 && up.tagName === 'EM' - && twoup.childNodes.length === 1 && twoup.tagName === 'P') { + && twoup.childNodes.length === 1 && twoup.tagName === 'P') { a.className = 'button secondary'; twoup.classList.add('button-container'); up.outerHTML = a.outerHTML; @@ -710,6 +710,7 @@ async function loadPage(doc) { // eslint-disable-next-line no-use-before-define await loadLazy(doc); // eslint-disable-next-line no-use-before-define + await loadAds(doc); loadDelayed(doc); } @@ -787,8 +788,8 @@ function buildRelatedStoriesBlock(main, tags) { const FULL_WIDTH_BLOCKS = ['carousel', 'carousel course', 'hero', 'news', 'player-feature', 'share', 'teaser', 'weather']; const sections = main.querySelectorAll(':scope > div'); const nonFullWidthSection = [...sections] - .find((section) => ![...section.children] // check section - .find((child) => FULL_WIDTH_BLOCKS.includes(child.className))); // check content in section + .find((section) => ![...section.children] // check section + .find((child) => FULL_WIDTH_BLOCKS.includes(child.className))); // check content in section let storiesSection = nonFullWidthSection; if (!storiesSection) { // if no section without full-width content, create one storiesSection = document.createElement('div'); @@ -1138,7 +1139,7 @@ export async function sendAnalyticsPageEvent() { const dl = window.dataLayer; const placeholders = await fetchPlaceholders(); const isUserLoggedIn = window.gigyaAccountInfo && window.gigyaAccountInfo != null - && window.gigyaAccountInfo.errorCode === 0; + && window.gigyaAccountInfo.errorCode === 0; const { pageName, sections } = getPageNameAndSections(); dl.push({ @@ -1157,6 +1158,83 @@ export async function sendAnalyticsPageEvent() { }); } +async function OptanonWrapper() { + const geoInfo = window.Optanon.getGeolocationData(); + Object.keys(geoInfo).forEach((key) => { + const cookieName = `PGAT_${key.charAt(0).toUpperCase() + key.slice(1)}`; + const cookie = getCookie(cookieName); + if (!cookie || cookie !== geoInfo[key]) document.cookie = `${cookieName}=${geoInfo[key]}`; + }); + + const prevOptIn = localStorage.getItem('OptIn_PreviousPermissions'); + if (prevOptIn) { + try { + const settings = JSON.parse(prevOptIn); + if (settings.tempImplied) { + localStorage.removeItem('OptIn_PreviousPermissions'); + } + } catch (e) { + // eslint-disable-next-line no-console + console.error('OptIn_PreviousPermissions parse failed'); + } + } + await sendAnalyticsPageEvent(); +} + +/* setup cookie preferences */ +function getCookie(cookieName) { + const name = `${cookieName}=`; + const decodedCookie = decodeURIComponent(document.cookie); + const split = decodedCookie.split(';'); + // eslint-disable-next-line no-plusplus + for (let i = 0; i < split.length; i++) { + let c = split[i]; + while (c.charAt(0) === ' ') c = c.substring(1); + if (c.indexOf(name) === 0) return c.substring(name.length, c.length); + } + return null; +} + +async function loadAds(doc) { + const placeholders = await fetchPlaceholders(); + const isProd = window.location.hostname.endsWith(placeholders.hostname); + if (!isProd === 'this') { + // temporary override for analytics testing + if (!localStorage.getItem('OptIn_PreviousPermissions')) localStorage.setItem('OptIn_PreviousPermissions', '{"aa":true,"mediaaa":true,"target":true,"ecid":true,"adcloud":true,"aam":true,"campaign":true,"livefyre":false}'); + } + const otId = placeholders.onetrustId; + if (otId) { + const cookieScript = loadScript('https://cdn.cookielaw.org/scripttemplates/otSDKStub.js'); + cookieScript.setAttribute('data-domain-script', `${otId}${isProd ? '' : '-test'}`); + cookieScript.setAttribute('data-dlayer-name', 'dataLayer'); + cookieScript.setAttribute('data-nscript', 'beforeInteractive'); + + const gtmId = placeholders.googletagmanagerId; + if (gtmId) { + const GTMScript = doc.createElement('script'); + GTMScript.innerHTML = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': + new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], + j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= + 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); + })(window,document,'script','dataLayer','${gtmId}');`; + doc.head.append(GTMScript); + + const GTMFrame = doc.createElement('no-script'); + GTMFrame.innerHTML = ``; + doc.body.prepend(GTMFrame); + } + + window.OptanonWrapper = OptanonWrapper; + + if (doc.querySelector('.marketing')) { + const marketingBlock = document.querySelector('.marketing'); + decorateBlock(marketingBlock); + await loadBlock(marketingBlock); + } + } +} + try { const hidden = Symbol('hidden'); const proxy = Symbol('proxy'); @@ -1178,3 +1256,4 @@ try { }, }); } catch (e) { /* ignore */ } + From 4ddfc67744a4d9f59ff0883dd784b4b10886f177 Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Sat, 6 Apr 2024 00:19:50 -0700 Subject: [PATCH 2/9] TDW-2277 minor code change --- scripts/scripts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 3fedbdb8..5bf99be3 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -1230,7 +1230,7 @@ async function loadAds(doc) { if (doc.querySelector('.marketing')) { const marketingBlock = document.querySelector('.marketing'); decorateBlock(marketingBlock); - await loadBlock(marketingBlock); + loadBlock(marketingBlock); } } } From 4d66e76d6917f8939f1711e5cb97e35a049431a7 Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Mon, 8 Apr 2024 12:07:22 -0700 Subject: [PATCH 3/9] TDW-2277 minor code change --- scripts/scripts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 5bf99be3..9ce78dab 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -10,6 +10,8 @@ * governing permissions and limitations under the License. */ +const placeholders = await fetchPlaceholders(); +const isProd = window.location.hostname.endsWith(placeholders.hostname); /** * log RUM if part of the sample. * @param {string} checkpoint identifies the checkpoint in funnel @@ -1196,8 +1198,6 @@ function getCookie(cookieName) { } async function loadAds(doc) { - const placeholders = await fetchPlaceholders(); - const isProd = window.location.hostname.endsWith(placeholders.hostname); if (!isProd === 'this') { // temporary override for analytics testing if (!localStorage.getItem('OptIn_PreviousPermissions')) localStorage.setItem('OptIn_PreviousPermissions', '{"aa":true,"mediaaa":true,"target":true,"ecid":true,"adcloud":true,"aam":true,"campaign":true,"livefyre":false}'); From 9da752b41faa4db009eed9d511b9c1e31038dca0 Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Mon, 8 Apr 2024 17:51:58 -0700 Subject: [PATCH 4/9] TDW-2277 moved fetchplaceholders call into the function --- scripts/scripts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 9ce78dab..5bf99be3 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -10,8 +10,6 @@ * governing permissions and limitations under the License. */ -const placeholders = await fetchPlaceholders(); -const isProd = window.location.hostname.endsWith(placeholders.hostname); /** * log RUM if part of the sample. * @param {string} checkpoint identifies the checkpoint in funnel @@ -1198,6 +1196,8 @@ function getCookie(cookieName) { } async function loadAds(doc) { + const placeholders = await fetchPlaceholders(); + const isProd = window.location.hostname.endsWith(placeholders.hostname); if (!isProd === 'this') { // temporary override for analytics testing if (!localStorage.getItem('OptIn_PreviousPermissions')) localStorage.setItem('OptIn_PreviousPermissions', '{"aa":true,"mediaaa":true,"target":true,"ecid":true,"adcloud":true,"aam":true,"campaign":true,"livefyre":false}'); From 06081868904640fbe752527271e38b9c446468aa Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Mon, 8 Apr 2024 18:00:54 -0700 Subject: [PATCH 5/9] TDW-2277 minor format change --- scripts/scripts.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 5bf99be3..0d2eda66 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -1158,6 +1158,20 @@ export async function sendAnalyticsPageEvent() { }); } +/* setup cookie preferences */ +function getCookie(cookieName) { + const name = `${cookieName}=`; + const decodedCookie = decodeURIComponent(document.cookie); + const split = decodedCookie.split(';'); + // eslint-disable-next-line no-plusplus + for (let i = 0; i < split.length; i++) { + let c = split[i]; + while (c.charAt(0) === ' ') c = c.substring(1); + if (c.indexOf(name) === 0) return c.substring(name.length, c.length); + } + return null; +} + async function OptanonWrapper() { const geoInfo = window.Optanon.getGeolocationData(); Object.keys(geoInfo).forEach((key) => { @@ -1181,20 +1195,6 @@ async function OptanonWrapper() { await sendAnalyticsPageEvent(); } -/* setup cookie preferences */ -function getCookie(cookieName) { - const name = `${cookieName}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const split = decodedCookie.split(';'); - // eslint-disable-next-line no-plusplus - for (let i = 0; i < split.length; i++) { - let c = split[i]; - while (c.charAt(0) === ' ') c = c.substring(1); - if (c.indexOf(name) === 0) return c.substring(name.length, c.length); - } - return null; -} - async function loadAds(doc) { const placeholders = await fetchPlaceholders(); const isProd = window.location.hostname.endsWith(placeholders.hostname); @@ -1256,4 +1256,3 @@ try { }, }); } catch (e) { /* ignore */ } - From 0275ccbeaba17e613cc3a8cf772eee97e5e5d95b Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Tue, 9 Apr 2024 12:05:19 -0700 Subject: [PATCH 6/9] TDW-2277 created dependencies.js file --- scripts/dependencies.js | 78 ++++++++++++++++++++++++++ scripts/scripts.js | 120 +++------------------------------------- 2 files changed, 85 insertions(+), 113 deletions(-) create mode 100644 scripts/dependencies.js diff --git a/scripts/dependencies.js b/scripts/dependencies.js new file mode 100644 index 00000000..919cb1f4 --- /dev/null +++ b/scripts/dependencies.js @@ -0,0 +1,78 @@ +// eslint-disable-next-line import/no-cycle +import { + decorateBlock, + fetchPlaceholders, + loadBlock, + loadScript, +} from './scripts.js'; + +const placeholders = await fetchPlaceholders(); +const isProd = window.location.hostname.endsWith(placeholders.hostname); + +/* setup cookie preferences */ +function getCookie(cookieName) { + const name = `${cookieName}=`; + const decodedCookie = decodeURIComponent(document.cookie); + const split = decodedCookie.split(';'); + // eslint-disable-next-line no-plusplus + for (let i = 0; i < split.length; i++) { + let c = split[i]; + while (c.charAt(0) === ' ') c = c.substring(1); + if (c.indexOf(name) === 0) return c.substring(name.length, c.length); + } + return null; +} + +async function OptanonWrapper() { + const geoInfo = window.Optanon.getGeolocationData(); + Object.keys(geoInfo).forEach((key) => { + const cookieName = `PGAT_${key.charAt(0).toUpperCase() + key.slice(1)}`; + const cookie = getCookie(cookieName); + if (!cookie || cookie !== geoInfo[key]) document.cookie = `${cookieName}=${geoInfo[key]}`; + }); + + const prevOptIn = localStorage.getItem('OptIn_PreviousPermissions'); + if (prevOptIn) { + try { + const settings = JSON.parse(prevOptIn); + if (settings.tempImplied) { + localStorage.removeItem('OptIn_PreviousPermissions'); + } + } catch (e) { + // eslint-disable-next-line no-console + console.error('OptIn_PreviousPermissions parse failed'); + } + } +} + +const otId = placeholders.onetrustId; +if (otId) { + const cookieScript = loadScript('https://cdn.cookielaw.org/scripttemplates/otSDKStub.js'); + cookieScript.setAttribute('data-domain-script', `${otId}${isProd ? '' : '-test'}`); + cookieScript.setAttribute('data-dlayer-name', 'dataLayer'); + cookieScript.setAttribute('data-nscript', 'beforeInteractive'); + + const gtmId = placeholders.googletagmanagerId; + if (gtmId) { + const GTMScript = document.createElement('script'); + GTMScript.innerHTML = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': + new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], + j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= + 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); + })(window,document,'script','dataLayer','${gtmId}');`; + document.head.append(GTMScript); + + const GTMFrame = document.createElement('no-script'); + GTMFrame.innerHTML = ``; + document.body.prepend(GTMFrame); + } + + window.OptanonWrapper = OptanonWrapper; + + if (document.querySelector('.marketing')) { + const marketingBlock = document.querySelector('.marketing'); + decorateBlock(marketingBlock); + loadBlock(marketingBlock); + } +} \ No newline at end of file diff --git a/scripts/scripts.js b/scripts/scripts.js index 0d2eda66..db25871d 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -710,7 +710,6 @@ async function loadPage(doc) { // eslint-disable-next-line no-use-before-define await loadLazy(doc); // eslint-disable-next-line no-use-before-define - await loadAds(doc); loadDelayed(doc); } @@ -1070,6 +1069,8 @@ async function loadLazy(doc) { addFavIcon(`${window.hlx.codeBasePath}/styles/favicon.ico`); doc.querySelectorAll('div:not([class]):not([id]):empty').forEach((empty) => empty.remove()); + // eslint-disable-next-line import/no-cycle + loadDependencies(); } /** @@ -1082,6 +1083,11 @@ function loadDelayed() { // load anything that can be postponed to the latest here } +function loadDependencies() { + // eslint-disable-next-line import/no-cycle + window.setTimeout(() => import('./dependencies.js'), 1000); +} + export async function lookupPages(pathnames) { if (!window.pageIndex) { const resp = await fetch('/query-index.json'); @@ -1123,118 +1129,6 @@ export function addHeaderSizing(block, classPrefix = 'heading', selector = 'h1, }); } -function getPageNameAndSections() { - const pageSectionParts = window.location.pathname.split('/').filter((subPath) => subPath !== ''); - const pageName = pageSectionParts.join(':'); - const finalPageName = pageName === '' ? 'Home' : pageName; - - return { - pageName: finalPageName, - sections: pageSectionParts, - }; -} - -export async function sendAnalyticsPageEvent() { - window.dataLayer = window.dataLayer || []; - const dl = window.dataLayer; - const placeholders = await fetchPlaceholders(); - const isUserLoggedIn = window.gigyaAccountInfo && window.gigyaAccountInfo != null - && window.gigyaAccountInfo.errorCode === 0; - - const { pageName, sections } = getPageNameAndSections(); - dl.push({ - event: 'pageload', - pageName, - pageUrl: window.location.href, - siteSection: sections[0] || '', - siteSubSection: sections[1] || '', - siteSubSection2: sections[2] || '', - gigyaID: isUserLoggedIn && window.gigyaAccountInfo.UID ? window.gigyaAccountInfo.UID : '', - userLoggedIn: isUserLoggedIn ? 'Logged In' : 'Logged Out', - tourName: placeholders.tourName.toLowerCase().replaceAll(' ', '_'), - tournamentID: `${placeholders.tourCode.toUpperCase()}${placeholders.currentYear}${placeholders.tournamentId}`, - ipAddress: '127.0.0.1', - deviceType: 'Web', - }); -} - -/* setup cookie preferences */ -function getCookie(cookieName) { - const name = `${cookieName}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const split = decodedCookie.split(';'); - // eslint-disable-next-line no-plusplus - for (let i = 0; i < split.length; i++) { - let c = split[i]; - while (c.charAt(0) === ' ') c = c.substring(1); - if (c.indexOf(name) === 0) return c.substring(name.length, c.length); - } - return null; -} - -async function OptanonWrapper() { - const geoInfo = window.Optanon.getGeolocationData(); - Object.keys(geoInfo).forEach((key) => { - const cookieName = `PGAT_${key.charAt(0).toUpperCase() + key.slice(1)}`; - const cookie = getCookie(cookieName); - if (!cookie || cookie !== geoInfo[key]) document.cookie = `${cookieName}=${geoInfo[key]}`; - }); - - const prevOptIn = localStorage.getItem('OptIn_PreviousPermissions'); - if (prevOptIn) { - try { - const settings = JSON.parse(prevOptIn); - if (settings.tempImplied) { - localStorage.removeItem('OptIn_PreviousPermissions'); - } - } catch (e) { - // eslint-disable-next-line no-console - console.error('OptIn_PreviousPermissions parse failed'); - } - } - await sendAnalyticsPageEvent(); -} - -async function loadAds(doc) { - const placeholders = await fetchPlaceholders(); - const isProd = window.location.hostname.endsWith(placeholders.hostname); - if (!isProd === 'this') { - // temporary override for analytics testing - if (!localStorage.getItem('OptIn_PreviousPermissions')) localStorage.setItem('OptIn_PreviousPermissions', '{"aa":true,"mediaaa":true,"target":true,"ecid":true,"adcloud":true,"aam":true,"campaign":true,"livefyre":false}'); - } - const otId = placeholders.onetrustId; - if (otId) { - const cookieScript = loadScript('https://cdn.cookielaw.org/scripttemplates/otSDKStub.js'); - cookieScript.setAttribute('data-domain-script', `${otId}${isProd ? '' : '-test'}`); - cookieScript.setAttribute('data-dlayer-name', 'dataLayer'); - cookieScript.setAttribute('data-nscript', 'beforeInteractive'); - - const gtmId = placeholders.googletagmanagerId; - if (gtmId) { - const GTMScript = doc.createElement('script'); - GTMScript.innerHTML = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': - new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], - j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= - 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); - })(window,document,'script','dataLayer','${gtmId}');`; - doc.head.append(GTMScript); - - const GTMFrame = doc.createElement('no-script'); - GTMFrame.innerHTML = ``; - doc.body.prepend(GTMFrame); - } - - window.OptanonWrapper = OptanonWrapper; - - if (doc.querySelector('.marketing')) { - const marketingBlock = document.querySelector('.marketing'); - decorateBlock(marketingBlock); - loadBlock(marketingBlock); - } - } -} - try { const hidden = Symbol('hidden'); const proxy = Symbol('proxy'); From 65c210f405f158771dbb252419fd0c8774bdb01a Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Tue, 9 Apr 2024 12:10:41 -0700 Subject: [PATCH 7/9] TDW-2277 called loadDependencies in loadPAge --- scripts/scripts.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index db25871d..c877c5ad 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -709,6 +709,8 @@ async function loadPage(doc) { await loadEager(doc); // eslint-disable-next-line no-use-before-define await loadLazy(doc); + // eslint-disable-next-line import/no-cycle + loadDependencies(); // eslint-disable-next-line no-use-before-define loadDelayed(doc); } @@ -1069,8 +1071,6 @@ async function loadLazy(doc) { addFavIcon(`${window.hlx.codeBasePath}/styles/favicon.ico`); doc.querySelectorAll('div:not([class]):not([id]):empty').forEach((empty) => empty.remove()); - // eslint-disable-next-line import/no-cycle - loadDependencies(); } /** @@ -1085,7 +1085,7 @@ function loadDelayed() { function loadDependencies() { // eslint-disable-next-line import/no-cycle - window.setTimeout(() => import('./dependencies.js'), 1000); + window.setTimeout(() => import('./dependencies.js'), 500); } export async function lookupPages(pathnames) { From 5d8e9b40940087dc4b36bd7d7a62d5f03b8ce6c2 Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Tue, 9 Apr 2024 12:12:50 -0700 Subject: [PATCH 8/9] TDW-2277 called loaddependenices before loadlazy --- scripts/scripts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index c877c5ad..1696a5af 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -707,11 +707,11 @@ async function waitForLCP() { async function loadPage(doc) { // eslint-disable-next-line no-use-before-define await loadEager(doc); - // eslint-disable-next-line no-use-before-define - await loadLazy(doc); // eslint-disable-next-line import/no-cycle loadDependencies(); // eslint-disable-next-line no-use-before-define + await loadLazy(doc); + // eslint-disable-next-line no-use-before-define loadDelayed(doc); } From 22601add577d8dc2dfe742e3e39222b668d91a35 Mon Sep 17 00:00:00 2001 From: bosco-ensemble Date: Tue, 9 Apr 2024 12:14:32 -0700 Subject: [PATCH 9/9] TDW-2277 removed loaddependencies function call --- scripts/scripts.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 1696a5af..420eae36 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -707,8 +707,6 @@ async function waitForLCP() { async function loadPage(doc) { // eslint-disable-next-line no-use-before-define await loadEager(doc); - // eslint-disable-next-line import/no-cycle - loadDependencies(); // eslint-disable-next-line no-use-before-define await loadLazy(doc); // eslint-disable-next-line no-use-before-define @@ -1079,15 +1077,11 @@ async function loadLazy(doc) { */ function loadDelayed() { // eslint-disable-next-line import/no-cycle + window.setTimeout(() => import('./dependencies.js'), 500); window.setTimeout(() => import('./delayed.js'), 4000); // load anything that can be postponed to the latest here } -function loadDependencies() { - // eslint-disable-next-line import/no-cycle - window.setTimeout(() => import('./dependencies.js'), 500); -} - export async function lookupPages(pathnames) { if (!window.pageIndex) { const resp = await fetch('/query-index.json');