-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs: insert canonical link dynamically #31830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
canonicalLink.setAttribute('rel', 'canonical'); | ||
canonicalLink.setAttribute('href', fullPath); | ||
|
||
const title = this._document.head.querySelector('title'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit convoluted. We can just do document.head.appendChild(canonicalLink)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that first but then thought that the search engine might not process the canonical (with the same priority) if it's at the very end of the long even below the long <script> tag. But given that this would be only for a search engine that runs JS - this is probably silly.
* docs: delete static canonical link * docs: insert, not update dynamic canonical link * docs: always append tag when inserted
* docs: delete static canonical link * docs: insert, not update dynamic canonical link * docs: always append tag when inserted
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
In the past we had a static canonical link to material.angular.dev/ for all pages that got dynamically updated to the correct URL.
However Search engines sometimes don't seem to parse the JS and in this case having the canonical point to material.angular.dev/ seems worse than having it not present as it prevents pages from being indexed.