From a9ec94cd89ae281adade29ac29a2f95c9e02c603 Mon Sep 17 00:00:00 2001 From: Alberto Di Cagno Date: Fri, 26 Jul 2024 16:55:35 +0200 Subject: [PATCH] fix: prevent soft 404 errors --- scripts/commerce.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/commerce.js b/scripts/commerce.js index fbb0637f8a..d30c1b6c83 100644 --- a/scripts/commerce.js +++ b/scripts/commerce.js @@ -304,6 +304,15 @@ export async function loadErrorPage(code = 404) { document.body.innerHTML = doc.body.innerHTML; document.head.innerHTML = doc.head.innerHTML; + // https://developers.google.com/search/docs/crawling-indexing/javascript/fix-search-javascript + // Point 2. prevent soft 404 errors + if (code === 404) { + const metaRobots = document.createElement('meta'); + metaRobots.name = 'robots'; + metaRobots.content = 'noindex'; + document.head.appendChild(metaRobots); + } + // When moving script tags via innerHTML, they are not executed. They need to be re-created. const notImportMap = (c) => c.textContent && c.type !== 'importmap'; Array.from(document.head.querySelectorAll('script'))