Prevent Googlebot from loading badges
What does this MR do and why?
Second attempt at fixing #1705 (closed)
In the first attempt to fix this (!4214 (merged)), which was reverted (!4220 (merged)), we introduced a new bug where badges could appear in the table of contents.
This MR makes the same change for the crawler issue: separates badges code from default.js, so that we can block it from bots. And to fix the bug from the last attempt, it wraps the badge code in a window.onload
event handler, which prevents it from running before ToC code. The ToC fires immediately on page load in the DOMContentLoaded
event (https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event).
Screenshots, screen recordings, or links to review app
No visual changes.
Here's a page with badges in a lower-level header: https://1705-googlebot-badge-block-redo.docs.gitlab-review.app/ee/update/zero_downtime.html#redis-ha-using-sentinel
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Configure a local GitLab Docs environment: https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/doc/setup.md.
-
Compile and view the site; verify badges still render as expected (and they do not show up in the ToC). -
As a way to (sort of) emulate Googlebot: Comment-out the include for badges.js
fromlayouts/default.html
and recompile; verify the page loads fine without the badges script (it will not show badges, but everything else works as normal).
Merge request acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this merge request.