Google clarifies canonicalization with JavaScript

Google clarifies canonicalization with JavaScript

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.


Barry SchwartzBarry Schwartz

Barry Schwartz is a technologist and a Contributing Editor to Search Engine Land and a member of the programming team for SMX events. He owns RustyBrick, a NY based web consulting firm. He also runs Search Engine Roundtable, a popular search blog on very advanced SEM topics.

In 2019, Barry was awarded the Outstanding Community Services Award from Search Engine Land, in 2018 he was awarded the US Search Awards the “US Search Personality Of The Year,” you can learn more over here and in 2023 he was listed as a top 50 most influential PPCer by Marketing O’Clock.

Barry can be followed on X here and you can learn more about Barry Schwartz over here or on his personal site.



#Google #clarifies #canonicalization #JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *