Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantics of relative URLs in schema.org Breadcrumbs in JSON-LD

The schema.org website gives an example of a breadcrumb represented in JSON-LD

<script type="application/ld+json">
{
 "@context": "http://schema.org",
 "@type": "BreadcrumbList",
 "itemListElement":
 [
  {
   "@type": "ListItem",
   "position": 1,
   "item":
   {
    "@id": "https://example.com/dresses",
    "name": "Dresses"
    }
  },
  {
   "@type": "ListItem",
  "position": 2,
  "item":
   {
     "@id": "https://example.com/dresses/real",
     "name": "Real Dresses"
   }
  }
 ]
}
</script>

Most of it is clear to me but I'm not absolutely certain about the semantics of the links provided in this example.

What I find confusing are the @id properties. Their values are URLs and it looks like these should lead to actual web pages linked to by the breadcrumb items. However, the name of the property suggests that the URLs might actually point to concept identifiers in some ontology. Which is it?

The Without Markup tab contains an unannotated piece of HTML suggesting that my first guess is correct and the URLs actually lead to web pages.

<ol>
  <li>
    <a href="https://example.com/dresses">Dresses</a>
  </li>
  <li>
    <a href="https://example.com/dresses/real">Real Dresses</a>
  </li>
</ol>

Is this the case and is it okay to use relative URLs in this context?

<script type="application/ld+json">
{
 "@context": "http://schema.org",
 "@type": "BreadcrumbList",
 "itemListElement":
 [
  {
   "@type": "ListItem",
   "position": 1,
   "item":
   {
    "@id": "https://dresses.com/dresses",
    "name": "Dresses"
    }
  },
  {
   "@type": "ListItem",
  "position": 2,
  "item":
   {
     "@id": "/dresses/cocktail",
     "name": "Cocktail Dresses"
   }
  }
 ]
}
</script>
like image 899
toniedzwiedz Avatar asked Jul 18 '16 10:07

toniedzwiedz


People also ask

What is breadcrumb schema?

A set of links that can help a user understand and navigate a website hierarchy.

What is schema JSON-LD?

JSON-LD is a lightweight Linked Data format to easily read and write structured data on the web using open vocabularies like schema.org. Recommended by the World Wide Web Consortium, JSON-LD is the heir of the JSON format and allows linked data to operate in a Web-scale environment.

What is base URL and relative URL?

A URL specifies the location of a target stored on a local or networked computer. The target can be a file, directory, HTML page, image, program, and so on. An absolute URL contains all the information necessary to locate a resource. A relative URL locates a resource using an absolute URL as a starting point.

Should I use absolute or relative URLs?

If you do a lot of testing and move content frequently between domains, then relative links are the best solution. Absolute paths are more secure, protect content, and prevent duplicate pages. The main point is that the link format you prefer should be applied to all URLs on the site.


3 Answers

I had the same question and end up doing research which I documented on https://sergeyski.com/relative-urls-in-structured-data/. Key part is this:

If you paste markup directly into google validator and there is a relative path - validator doesn't know which domain it belongs to and just appends its own domain (https://search.google.com). Once you deploy changes and test with real url you'll see that validator will append correct domain, so you can definitely use relative urls in structured data.

like image 191
sergeyski.com Avatar answered Oct 12 '22 12:10

sergeyski.com


Is this the case and is it okay to use relative URLs in this context?

Over at GitLab, we were confused by this too (see relevant issue) since Google's Rich Results Test blows up with relative URL's, but there are historic examples of relative URL's working in production.

So, we tried it out. We pushed some json+ld with relative URL's to production and one of our engineers received an alert that the id field was invalid.

Short answer - no it is not okay to use relative URL's for json+ld (but is okay to have relative URL's for markup, see this comment) and Google clearly expects absolute URL's. If it happens to work now, there's no guarantee that it will in the future.

like image 38
souldzin Avatar answered Oct 12 '22 14:10

souldzin


All URLs should be absolute. You can use the official testing tool https://search.google.com/structured-data/testing-tool/u/0/ that is going to give an error in relative URLs.

like image 24
Christian Avatar answered Oct 12 '22 12:10

Christian