JavaScript does not change the canonical URL unintentionally
- Check
- Compares the canonical URL in the initial and rendered HTML of the same page state. Fails when JavaScript sets a conflicting target; relative and absolute forms of the same URL count as equal.
- Fix
- Serve the correct canonical URL from the start and fix the hydration code that overwrites it.
- Google allows setting the canonical URL with JavaScript but explicitly advises against changing it to a URL other than the one in the initial HTML.
- Understand JavaScript SEO Basics, updated 4 March 2026
rendering.canonical-stableRevision 1changed