Google clarifies canonicalization with JavaScript
Google added a section on canonicalization best practices for JavaScript to the JavaScript SEO best practices document.
Google updated its JavaScript SEO best practices document, for the second time this week, this time to clarify canonicalization best practices for JavaScript. In short, Google said “setting the canonical URL to the same URL as in the original HTML or if that isn’t possible, to leave the canonical URL out of the original HTML.”
What Google added. Google added a new section over here and it reads:
“The rel=”canonical” link tag helps Google find the canonical version of a page. You can use JavaScript to set the canonical URL, but keep in mind that you shouldn’t use JavaScript to change the canonical URL to something else than the URL you specified as the canonical URL in the original HTML. The best way to set the canonical URL is to use HTML, but if you have to use JavaScript, make sure that you always set the canonical URL to the same value as the original HTML. If you can’t set the canonical URL in the HTML, then you can use JavaScript to set the canonical URL and leave it out of the original HTML.”
Google on noindex. Google also warned about using JavaScript for noindex tags earlier this week. Google said “you do want the page indexed, don’t use a noindex tag in the original page code.”
Why we care. So if you use JavaScript for setting a canonical link, make sure to also check in Google Search Console’s URL Inspection tool if it is being picked up.
Review these updated best practices if you use JavaScript on your site, especially for canonical links.
Search Engine Land is owned by Semrush. We remain committed to providing high-quality coverage of marketing topics. Unless otherwise noted, this page’s content was written by either an employee or a paid contractor of Semrush Inc.