Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JSON-LD have to be embedded?

We are currently using the Microdata format to expose data to search engines and we are looking at exposing more info to be able to support some more advanced Google Search features. As I'm working my way through the fields I'm finding I need information that we currently load asynchronously so it is not a part of the initial response.

JSON-LD looks like its what Google prefers but all the examples I've seen have it embedded in the page. Could you have a link to a JS file so it gets loaded as a separate call? Something like

<script type="application/ld+json" src="/myid123/jsonld.js"></script> 
like image 385
Ryan B Avatar asked Jun 16 '15 10:06

Ryan B


People also ask

Where should Ld JSON be placed?

Google recommends adding JSON-LD to the <head> section of the HTML document; however, it's okay if the JSON-LD is within the <body> section. Google can also grasp dynamically generated tags in the DOM.

Does JSON-LD have to be in head?

In response, Mueller says “yes.” JSON-LD structured data can absolutely be inserted in either the head or body of the page. Just as the person who submitted the question assumed – it will work fine either way. JSON-LD can also be inserted into pages using JavaScript, if that's what happens to suit your pages better.

Is JSON-LD related to JSON?

JSON-LD is a lightweight Linked Data format. It is easy for humans to read and write. It is based on the already successful JSON format and provides a way to help JSON data interoperate at Web-scale.


1 Answers

If you are using the script element as data block, "the src attribute must not be specified".

If the script element is not used as data block, it has to be "used to include dynamic scripts". But a JSON-LD document is not a dynamic script.

For linking to another resource, just like you do it with external stylesheets or Favicons, you can use the link element in the head (or the corresponding HTTP header):

<link href="/myid123/jsonld.js" rel="alternate" type="application/ld+json" /> 

In principle, consumers could follow this reference (possibly only if a certain link type is specified), and make use of data, just like they do it with embedded JSON-LD, Microdata, or RDFa.

However, consumers don’t have to do this, of course, and many probably don’t.
Google Search in particular does not claim to support it for consuming Schema.org in the JSON-LD format. However, they claim to support "dynamically injected" JSON-LD data blocks.

like image 117
unor Avatar answered Oct 07 '22 20:10

unor