From d8c040b6af33f7192074b9f74161ba235f00548e Mon Sep 17 00:00:00 2001 From: TyroneAEM <147942284+TyroneAEM@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:50:12 -0500 Subject: [PATCH] ASSETS-88922 : Review the Deliverable page load time (#130) * Improve page load time by parallelizing API calls and adding debug logs - Updated `decorate` function to fetch program details and deliverables in parallel using `Promise.all`. - Added console logs before and after API calls to help with debugging. - Maintained existing functionality while optimizing performance by reducing sequential API calls. * Remove logging messages * feat: Improve performance of gmo-program-details.js - Implement parallel GraphQL queries to reduce load times. - Lazy load images using the `loading="lazy"` attribute to improve initial load performance. - Batch DOM updates using `document.createDocumentFragment()` to minimize reflows and repaints. - Debounce event listeners to prevent performance issues caused by rapid firing of events. These optimizations should enhance the overall performance and responsiveness of the page. * Optimize header rendering and asynchronous data fetching - Initiate parallel fetching of program details and deliverables. - Render a placeholder header immediately to improve perceived load time. - Update header with actual data once program details are fetched. - Ensure images are loaded asynchronously without blocking header rendering. * feat: Inject additional HTML content into main-body-wrapper after header update - Added HTML content including tab-wrapper, overview, and deliverables sections to the main-body-wrapper div after the header. - Updated the main-body-wrapper div to include newly provided HTML content for improved user interface and navigation. - Ensured the content injection occurs after the header update to maintain correct rendering order. * Added back displaying the back button with arrow icon and program name not available message and no data available message when program * Updated logic to display the total asset count for an image * Reverted back to const programData = await executeQuery(programQueryString); const deliverables = await executeQuery(deliverableQueryString); * Restored constant variables for Marketing Goal, KPIs, Target Market, Audiences const p0TargetMarketArea = program.p0TargetMarketArea; const p1TargetMarketArea = program.p1TargetMarketArea; const kpis = buildKPIList(program).outerHTML; const targetMarketAreas = buildTargetMarketAreaList(p0TargetMarketArea,p1TargetMarketArea).outerHTML; const audiences = buildAudienceList(program).outerHTML; const artifactLinks = buildArtifactLinks(program).outerHTML; To make the code more readable, they were removed when the structure of the code was refactored to incrementally build the block.innerHTML, to make the page appear to load faster. --- .../gmo-program-details.js | 132 +++++++++++------- 1 file changed, 82 insertions(+), 50 deletions(-) diff --git a/blocks/gmo-program-details/gmo-program-details.js b/blocks/gmo-program-details/gmo-program-details.js index e493bcd7..8feafeb6 100644 --- a/blocks/gmo-program-details/gmo-program-details.js +++ b/blocks/gmo-program-details/gmo-program-details.js @@ -14,12 +14,47 @@ const platformMappings = getMappingArray('platforms'); export default async function decorate(block) { const encodedSemi = encodeURIComponent(';'); const encodedProgram = encodeURIComponent(programName); + + blockConfig = readBlockConfig(block); + const programQueryString = `getProgramDetails${encodedSemi}programName=${encodedProgram}${encodedSemi}programID=${encodeURIComponent(programID)}`; + const deliverableQueryString = `getProgramDeliverables${encodedSemi}programName=${encodedProgram}${encodedSemi}programID=${encodeURIComponent(programID)}`; + + // Immediately render a placeholder header + block.innerHTML = ` +
+