1

What are the advantages and disadvantages of serving JSON data as text/javascript to a web browser compared to the official standard: application/json ?

I'm only asking this question because facebook is returning JSON data as text/javascript instead of the official standard application/json (example, example, example) and i would like to know what may be the reason behind this decision.

Community
  • 1
  • 1
Pacerier
  • 76,400
  • 86
  • 326
  • 602

3 Answers3

2

As mentioned in some other question, returning JSON with a text MIME type is neccessary if you want to upload files using the HTML4 method: submit your upload form to an iframe, and get the JSON response by extracting the iframe's innerHTML.

With MIME type application/json, browsers will offer to save the JSON instead of displaying it.

Personally, I always use text/plain, there is no disadvantage.

user123444555621
  • 130,762
  • 25
  • 104
  • 122
1

A mime type application would force the browser to save it to disk. Maybe Facebook doesn't want this? But I don't see an advantage or disadvantage.

Gigamegs
  • 12,342
  • 7
  • 31
  • 71
1

I would say in general, there is no advantage/disadvantage. If you were downloading the code, maybe the browser might try to interpret the mime type. Or if you are building an application using the mime types and want to handle it a certain way.

For purposes of facebook is doing, there wouldn't be any advant/disadvant

Senica Gonzalez
  • 7,310
  • 14
  • 61
  • 101