Mobile app version of vmapp.org
Login or Join
Welton855

: Linking external JSON-LD schema (from Schema.org) I have schemas in JSON-LD as per Schema.org. When it was inline (within <script> tags), the Google structured data testing tool recognised

@Welton855

Posted in: #GoogleRichSnippetsTool #JsonLd #SchemaOrg #Script

I have schemas in JSON-LD as per Schema.org. When it was inline (within <script> tags), the Google structured data testing tool recognised the schema successfully.

If I link it externally, for example: <script src="json/main-schema.json" type="application/ld+json"></script> the structured data testing tool doesn't recognise it.

Is this something I should be worried about?



How I had the working schema (example from Schema.org):

<script type="application/ld+json">
{ "@context" : "http://schema.org",
"@type" : "Organization",
"url" : "http://www.your-company-site.com",
"contactPoint" : [
{ "@type" : "ContactPoint",
"telephone" : "+1-401-555-1212",
"contactType" : "customer service"
} ] }
</script>


External schema layed out in main-schema.json, linked with <script src="json/main-schema.json" type="application/ld+json"></script>:

{ "@context" : "http://schema.org",
"@type" : "Organization",
"url" : "http://www.your-company-site.com",
"contactPoint" : [
{ "@type" : "ContactPoint",
"telephone" : "+1-401-555-1212",
"contactType" : "customer service"
} ] }

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Welton855

2 Comments

Sorted by latest first Latest Oldest Best

 

@Nimeshi995

unor’s answer sums it up, but I also want to add:

From the spec:


Setting the [type] attribute to any other value [other than a JavaScript MIME type] means that the script is a data block, which is not processed. None of the <script> attributes (except type itself) have any effect on data blocks. Authors must use a valid MIME type that is not a JavaScript MIME type to denote data blocks.


So, in other words, if you have a <script> with a type attribute set to anything other than text/javascript (or an equivalent JavaScript MIME type), then all attributes, including src, will have no effect.

10% popularity Vote Up Vote Down


 

@Ogunnowo487

The script element can be used for two things:


dynamic/classic scripts
data


And for data, the spec defines:


When used to include data blocks, the data must be embedded inline […]


So you may use the src attribute only for scripts, not for data.

→ As JSON-LD is data, you have to inline it.

While linking a JSON-LD file is possible with the link element, the Schema.org sponsoring search engines don’t seem to support it.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme