I see that several can be used but I don't understand their differences or when I should use one or the other, for example:
text/javascript
text/x-javascript
text/x-json
application/json
application/x-javascript
I see that several can be used but I don't understand their differences or when I should use one or the other, for example:
text/javascript
text/x-javascript
text/x-json
application/json
application/x-javascript
According to section 11 of RFC7159: The JavaScript Object Notation (JSON) Data Interchange Format , the correct one is
application/json
:In the case of the others, the uses are as follows:
text/javascript
. It's obsolete, don't use ittext/x-javascript
It was an experimental content-type, it shouldn't be used either.text/x-json
Also experimental. not use itapplication/x-javascript
Experimental like the others with prefixx-
. not use itIt is also worth mentioning that an alternative that is not mentioned is
application/javascript
. This content-type should be used for JavaScript not to be confused with JSON .As far as I know, if you're going to transmit JSON over an HTTP service, you should use the content type
application/json
and it's backed by the official internet protocol standard RFC 4627For
JSON
pure it should be usedapplication/json
and for the case ofJSONP
it should be usedapplication/javascript