9

Where is the best place to put Schema.org markup that uses JSON-LD? Some recommend inside <head> but scripts work inline too. It would be easier in an MVC to put them in the same scope as the controllers, so that means inline near their element. But JSON-LD may "work better" as one huge script/stack in the <head>. I am just unsure of the ideal location I suppose.

Example would be breadcrumbs - should I just put the JSON-LD script before the markup for the crumbs, or should I go through all the trouble of loading up the models (again) to define them in the area creating the <head>? Seems like it would be a performance hit, but if its worth it for the spec, then it needs to be done.

Here is an example of Organization in JSON-LD (this would be in <head> already):

<script type="application/ld+json"> {
"@context" : "http://schema.org",
"@type" : "Organization",
"name" : "A Huge Corporation",
"url" : "http://www.example.com",
"logo" : "http://www.example.com/huge-corporation.png",
"founder" : "Humanz",
"foundingDate" : "1268",
"sameAs" : "http://plus.google.com/111111111111111111111",
"contactPoint" : {
    "@type" : "ContactPoint",
    "contactType" : "Customer Service",
    "telephone" : "+1-888-888-8888",
    "faxNumber" : "+1-777-777-7777",
    "contactOption" : "TollFree",
    "areaServed" : "US",
    "availableLanguage" : "English",
    "email" : "dude@example.com"
},
"hasPos" : {
    "@type" : "Place",
    "name" : "The Branch or Store",
    "photo" : "http://www.example.com/store.png",
    "hasMap" : {
        "@type" : "Map",
        "url" : "https://maps.google.com/maps?q=feed_me_a_map"
    },
    "address" : {
        "@type" : "PostalAddress",
        "name" : "The Branch or Store",
        "streetAddress" : "1547 Main Street",
        "addressLocality" : "Beverly Hills",
        "addressRegion" : "CA",
        "postalCode" : "90210",
        "addressCountry" : "United States"
    }
}}
</script>

And here is the breadcrumb snippet (currently resides in another scope, further down the page near the visually rendered crumbs). Would be nice to get this in head, if the work is worth it:

<script type="application/ld+json"> {
"@context" : "http://schema.org",
"@type" : "Breadcrumblist",
"itemListElement" : [
    {
    "@type" : "ListItem",
    "position" : 1,
    "item" : {
        "@id" : "http:www.example.com",
        "name" : "Home"
        }
    },
    {
    "@type" : "ListItem",
    "position" : 2,
    "item" : {
        "@id" : "http:www.example.com/widgets",
        "name" : "Widgets"
        }
    },
    {
    "@type" : "ListItem",
    "position" : 3,
    "item" : {
        "@id" : "http:www.example.com/widgets/green",
        "name" : "Green Widgets"
        }
    }
]}
</script>
8

JSON-LD doesn’t care. Which makes sense, because the data is the same, no matter from where in the document it gets extracted.

From the perspective of HTML, you should only include it in the head if the JSON-LD is about your web page or about what your web page represents, because the head element is defined to contain metadata for the document. But it’s not always easy to define if something counts as metadata or not; I wouldn’t worry too much about this.

  • Makes sense about the <head> thought -- will prob end up leaving organization up there....i think it counts as "meta" enough in the sense its on every single page and provides an identifiable "tag" per-say. – dhaupin Feb 25 '15 at 14:58
  • and in the head, is not a further piece of code blocking the page rendering? I was wondering that before the </body> could be better because of that – João Pimentel Ferreira Feb 6 '18 at 20:32
  • 1
    @JoãoPimentelFerreira: I would expect that it doesn’t block, because it’s a data block, not a script (both of these use the script element, but they are technically different cases). Browsers could totally ignore any data block. But I don’t know what browsers actually do. – unor Feb 6 '18 at 22:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.