json-ld.org icon indicating copy to clipboard operation
json-ld.org copied to clipboard

When using JSON-LD in a browser it is impossible to discover the Base IRI after a redirect

Open graingert opened this issue 12 years ago • 7 comments

When using JSON-LD in a browser (XMLHttpRequest) it is impossible to discover the Base IRI after a redirect because the XHR object hides the final URL of the resource.

This means documents without an explicit base URI cannot be resolved into triples in a browser

graingert avatar Feb 05 '14 16:02 graingert

True. There may be a messy iframe workaround that could grab the final URL, but I'm not sure.

dlongley avatar Feb 05 '14 17:02 dlongley

But if you

<iframe src="http://id.ecs.soton.ac.uk/person/1650" />

Then it will redirect to http://www.ecs.soton.ac.uk/people/wh rather than http://rdf.ecs.soton.ac.uk/person/1650 or http://json-ld.ecs.soton.ac.uk/person/1650 then it will end up on "http://id.ecs.soton.ac.uk/person/1650" and not .ecs.soton.ac.uk/person/1650

because the iframe dictates the content type and will break content negotiation accordingly

graingert avatar Feb 05 '14 17:02 graingert

Yeah, this is a general problem we discussed while working on the spec a while back -- one that we ultimately decided we'd have to live with. Our hope is that a future spec allows redirects to be disabled (and thus implemented in app) or that a final URL property is made available.

See:

http://stackoverflow.com/questions/3820663/is-it-possible-for-xhr-head-requests-to-not-follow-redirects-301-302/3820753#3820753

Possible iframe workaround:

http://stackoverflow.com/questions/16430901/get-final-url-from-xhr-object-after-redirect

But, as you noted, content-negotiation is up to the iframe -- and even if it works and you get back application/ld+json, current browsers don't know how to display that so a download dialog box is opened instead of displaying the document and allowing the URL to be captured.

dlongley avatar Feb 05 '14 18:02 dlongley

Would it be possible to add a reference to http://www.w3.org/TR/2008/WD-XMLHttpRequest-20080415/#notcovered and some text describing this problem in the http://www.w3.org/TR/json-ld/#base-iri section?

graingert avatar Feb 05 '14 18:02 graingert

@graingert http://www.w3.org/TR/json-ld/ is frozen, there will be no updates or additions to the specification for a long time (2+ years). We could add what you mention to the Errata, but even then, it's not an error. We could update the live version of the spec w/ this information (which is probably what we should do): http://www.w3.org/TR/json-ld/ (or the API document)

msporny avatar Feb 05 '14 18:02 msporny

Hmm... it’s a limitation of JavaScript in the browser. I don’t see that as an error of JSON-LD. Maybe you/we should file an issue against XMLHttpRequest2 instead!?

lanthaler avatar Feb 05 '14 19:02 lanthaler

Yes it's a limitation of JS in the browser, but that's the main use of JSON documents.

graingert avatar Feb 06 '14 09:02 graingert