Skip to content

Commit

Permalink
fix: prevent soft 404 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dicagno committed Jul 26, 2024
1 parent 040cd07 commit a9ec94c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/commerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit a9ec94c

Please sign in to comment.