Best content type to serve JSONP?

JavascriptJsonJsonp

Javascript Problem Overview


I have a webservice that when called without specifying a callback will return a JSON string using application/json as the content type.

When a callback is specified it will wrap the JSON string in a callback function, so it's not really valid JSON anymore. My question is, should I serve it as application/javascript in this case or still use application/json?

Javascript Solutions


Solution 1 - Javascript

Use application/javascript. In that way, clients can rely on the content-type without having to manually check whether a response has padding or not.

Solution 2 - Javascript

Use application/json as per rfc4627.txt if what you return is plain JSON.

If you return JavaScript (which is really what JSONP is), then use application/javascript as per rfc4329.txt

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZachView Question on Stackoverflow
Solution 1 - JavascriptJohn MillikinView Answer on Stackoverflow
Solution 2 - JavascriptFlorian BöschView Answer on Stackoverflow