Google has updated the JavaScript SEO help documentation with more technical details on how to insert canonical link tags using JavaScript. Google has added a new section entitled “Properly insert rel=”canonical” link tags”.
what’s new This is a new section where Google recommends against implementing canonical tags using JavaScript, but Google explains that if you need to do so, this is the right way to go. Google writes:
We don’t recommend using JavaScript for this, but it is possible to inject a rel=”canonical” link tag in JavaScript. Google Search gets the canonical URL inserted when the page is rendered. Below is an example of inserting a rel=”canonical” link tag in JavaScript.

Google added a warning “If you use JavaScript to insert a rel=”canonical” link tag, make sure this is the only rel=”canonical” link tag on the page” . Improper implementation can create multiple rel=”canonical” link tags or modify existing rel=”canonical” link tags. Conflicting or multiple rel=”canonical” link tags can lead to unexpected results. ”
Hit and miss. We’ve seen cases where Google can retrieve these standard tags and other embedded elements, as well as structured data, using JavaScript. However, things can go wrong, so we recommend that you follow these instructions exactly when using JavaScript to insert canonical tags.
why you care. Again, when using JavaScript to inject standard tags, Google has finally officially documented the proper way to implement it. Check the documentation here to make sure your implementation follows Google’s recommendations.

What’s New in Search Engine Land