Skip to content

feat(frontend): Skip consent manager scripts for search engine bots#478

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/add-noindex-for-internal-scripts
Closed

feat(frontend): Skip consent manager scripts for search engine bots#478
Copilot wants to merge 2 commits into
mainfrom
copilot/add-noindex-for-internal-scripts

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

content="noindex" is not valid on <script> tags and Googlebot executes JavaScript regardless of custom attributes. The correct SEO mitigation is to detect crawlers by User-Agent and skip delivering the consent manager output entirely.

Changes

lib/Utility.php — new Utility::isBot() static method:

  • Matches against a curated list of known crawler UA patterns (Googlebot, Bingbot, BaiduSpider, YandexBot, SemrushBot, AhrefsBot, etc.)
  • Uses preg_quote() to safely escape each pattern before regex assembly
  • Accepts an optional $userAgent string; falls back to HTTP_USER_AGENT
  • Marked @api

fragments/ConsentManager/box_cssjs.php — early return for bots:

if (Utility::isBot()) {
    return;
}

Placed after the existing guard checks, this skips all CSS/JS output — including Google Consent Mode scripts — when the visitor is identified as a crawler.

Original prompt

This section details on the original issue you should resolve

<issue_title>noindex für interne scripts</issue_title>
<issue_description>

$consentparams['outputjs'] .= ' <script nonce="' . rex_response::getNonce() . '" src="' . rex_url::frontendController($_params) . '" id="consent_manager_script" defer></script>' . PHP_EOL;

Kunde hat sich hier für SEO noindex gewünscht. Nach Anpassung:

$consentparams['outputjs'] .= ' <script nonce="' . rex_response::getNonce() . '" src="' . rex_url::frontendController($_params) . '" id="consent_manager_script" defer content="noindex"></script>' . PHP_EOL;

vielleicht kann das in Zukunft mit einfließen.</issue_description>

Comments on the Issue (you are @copilot in this section)

@skerbis content="noindex" ist nicht gültig für script

Einige Entwickler denken fälschlicherweise, man könne damit gezielt verhindern, dass Google den Inhalt eines Skripts "liest". Aber:

Crawler führen JavaScript aus: Googlebot führt Skripte aus, um den finalen Inhalt der Seite zu sehen. Ein erfundenes Attribut hält ihn nicht davon ab.

@thielpeter > content="noindex" ist nicht gültig für script > > Einige Entwickler denken fälschlicherweise, man könne damit gezielt verhindern, dass Google den Inhalt eines Skripts "liest". **Aber:** > > Crawler führen JavaScript aus: Googlebot führt Skripte aus, um den finalen Inhalt der Seite zu sehen. Ein erfundenes Attribut hält ihn nicht davon ab.

Danke für den Hinweis @skerbis Gibt es eine Alternative?</comment_new>
<comment_new>@skerbis
Nein ... oder kein Consent Manager oder kein JS ... hmm checken ob bot und nicht ausliefern

@thielpeter Hm und inline ist hier auch nicht möglich?

⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Co-authored-by: skerbis <791247+skerbis@users.noreply.github.com>
Copilot AI changed the title [WIP] Add noindex for internal scripts as requested by customer feat(frontend): Skip consent manager scripts for search engine bots Mar 19, 2026
Copilot AI requested a review from skerbis March 19, 2026 23:06
@skerbis skerbis closed this Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

noindex für interne scripts

2 participants