I initially wrote some code that created the structured data for breadcrumb and product markup on the server's side and rendered them in the <body>
of the page. While the mark up was correct according to Google's Structured Data Testing Tool, I saw no difference in the SERPs and when I opted to "fetch by URL" instead of "snippet" the tool was fetching only the <head>
of the given page's URL, so no structured data were being detected.
This was confusing, as in Google's documentation it is stated that the structured data can be inserted in the body
or head
of an HTML page.
I switched my approach and decided to place the product structured data in the <head>
section, while leaving the breadcrumb structured data to be rendered as it was. I read in the documentation that there is no problem if you append the data dynamically by JavaScript or AJAX, so I wrote a script that creates the structured data and appends them at the <head>
of the page.
When I tested my new links by "fetch URL" option, Google's tool was fetching the whole page (which it did not do before) but was not displaying the product structured data. This time however, it was fetching the breadcrumb data, which it did not do before and without changing anything in my code.
- Why was the tool initially fetching only the
<head>
but not the<body>
? - Why is the tool later also fetching the
<body>
part? - Why is the product mark up not displaying when the page if fetched by URL? Can it be that, contradictory to the documentation, the structured mark up is not detected when appended by JavaScript?
The JavaScript code that creates and appends the product mark up to the <head>
runs on document.ready
. The breadcrumb mark up renders together with the HTML during runtime.