diff --git a/prerender.cjs b/prerender.cjs index 72e21d2..4761e51 100644 --- a/prerender.cjs +++ b/prerender.cjs @@ -202,7 +202,8 @@ const renderProductWorker = async (productSeoNames, workerId, progressCallback, combinedMetaTags, true, config, - true // Suppress logs during parallel rendering to avoid interfering with progress bar + true, // Suppress logs during parallel rendering to avoid interfering with progress bar + productDetails // Pass product data for cache population ); if (success) { diff --git a/prerender/renderer.cjs b/prerender/renderer.cjs index f5640d4..d5a9c67 100644 --- a/prerender/renderer.cjs +++ b/prerender/renderer.cjs @@ -17,7 +17,8 @@ const renderPage = ( metaTags = "", needsRouter = false, config, - suppressLogs = false + suppressLogs = false, + productData = null ) => { const { isProduction, @@ -203,6 +204,21 @@ const renderPage = ( `; } + // Create script to populate window.productDetailCache for individual product pages + let productDetailCacheScript = ''; + if (productData && productData.product) { + const productDetailCacheData = JSON.stringify(productData.product); + productDetailCacheScript = ` + + `; + } + // Combine all CSS (global + inlined) into a single optimized style tag const combinedCss = globalCss + (inlinedCss ? '\n' + inlinedCss : ''); const combinedCssTag = combinedCss ? `` : ''; @@ -214,7 +230,7 @@ const renderPage = ( template = template.replace( "", - `${resourceHints}${combinedCssTag}${additionalTags}${metaTags}${prerenderFallbackScript}${productCacheScript}` + `${resourceHints}${combinedCssTag}${additionalTags}${metaTags}${prerenderFallbackScript}${productCacheScript}${productDetailCacheScript}` ); const rootDivRegex = /