Skip to content

JavaScript Canonicals: Compare the Original HTML and Rendered Head

Inspect three canonical outcomes in Chrome. Catch a script that appends a conflicting URL or replaces the preferred URL without changing the count.

Two overlapping kettle catalogue prints with a clear layer and offset violet markers
Jack Lee
2 Min Read
Share
On This Page

The page source names the kettle collection as canonical. After a script starts, could the same page point to the entire catalogue? One browser inspection can miss either half of that change.

Capture the original head and the live head

Open DevTools, switch to Network and reload the page. Select the main HTML document. In its Response tab, find each canonical link in the head and record its href. Then inspect the live head in Elements after the page has finished its usual updates. This console expression lists every current value:

Array.from(document.head.querySelectorAll('link[rel~="canonical"]'), link => link.href)

Compare both the count and the target

We served three local kettle pages to Chrome. Each response started with one canonical pointing to /kettles/. The table abbreviates the paths on the same example host.

CaseOriginal HTMLRendered head
Stable/kettles//kettles/
Appended/kettles//kettles/ and /all/
Replaced/kettles//all/

In the appended case the script added a second, conflicting destination. In the replacement case the final count stayed at one, but the destination changed. These are observations about Chrome’s DOM. Neither identifies the URL Google selected for indexing.

Put the preferred destination in one place

For this kettle collection, keep the intended collection URL in the server template. Find the script or plugin that writes the second value and stop it from overriding the template. Reload, wait for the catalogue to initialize and check again. The pass condition is one intended URL in the response and the same one in the live head.

Google recommends declaring the canonical in the original HTML when possible. If you must inject it with JavaScript, keep a single consistent declaration. For an unexpected selection in Search Console, compare signals with the Google-selected canonical guide. For other content changes during rendering, see the JavaScript SEO guide.

Frequently asked questions

Does View Source show the final head?

It shows the delivered markup. Inspect Elements for the DOM after scripts run.

Is finding one canonical enough?

Check its destination in both places. In the replacement example each view had one, but the URLs differed.

Can Chrome tell me which URL Google selected?

It shows the browser’s DOM. Check the indexed URL’s canonical details in Search Console for Google’s reported choice.

Share This Article