3

Is it possible to include JSON-LD or Microdata from a file in an HTML page?

I know it can be inserted directly, I'm looking for a way to use external files instead.

I can use either JSON-LD or Microdata format. I need to be able to include from a file, if possible, please advise.

unor
  • 92,415
  • 26
  • 211
  • 360
can.do
  • 475
  • 4
  • 14
  • Related questions: [Does JSON-LD have to be embedded?](http://stackoverflow.com/q/30864619/1591669) · [How to move JSON-LD from in-line to in-a-file?](http://stackoverflow.com/q/33236198/1591669) – unor Mar 24 '16 at 21:46
  • Do you have specific consumers for the structured data in mind? – unor Mar 24 '16 at 21:47
  • It's google structured data schema. – can.do Mar 24 '16 at 23:16

1 Answers1

0

You can dynamically embeded JSON-LD in HTML

Google can read JSON-LD data even when it is dynamically injected into the page's contents, such as by Javascript code or embedded "widgets".

but you can't just directly reference a JSON-LD file. You need to eventually embed it into the HTML. That should only require a couple of lines of JavaScript though.

Markus Lanthaler
  • 3,683
  • 17
  • 20
  • Do you have a specific way to implement that? Also it doesn't have to be jason-ld, microdata would work too. – can.do Mar 25 '16 at 15:42
  • Write a small JavaScript function which looks for `link` tags with `type="application/ld+json"` in the header, do a XHR request for each of them and embed the result in script blocks in your document. – Markus Lanthaler Mar 28 '16 at 17:50