JavaScriptResult content type

Mar 16, 2015 at 2:22 PM
Is there any special reason why JavaScriptResult sets ContentType to application/x-javascript?
As per RFC 4329 the use of application/javascript is now encouraged.
Is this behaviour perhaps related to legacy browser compatibility?
If so, maybe JavaScriptResult should use application/javascript and developers writing code that might be rendered in legacy browsers should use ContentResult and explicitly set content type to application/x-javascript instead of forcing developers deploying code meant for current browsers to do it the other way around.
Apr 15, 2015 at 1:13 AM
I think there's a very special reason - you're probably the first one to mention it! :)

The change would have to be made both on the server in the JavaScriptResult type, and also in the client in the unobtrusive AJAX script.

The latest version of the script is here and shows the lines that would have to change:

One thing I'm not sure of is whether jQuery supports "application/javascript" so we'd have to look into that. Currently the system assumes that it supports application/x-javascript.

Apr 15, 2015 at 8:04 PM
Edited Apr 16, 2015 at 5:12 PM
Ok, so jQuery 1.8, the minimum version required for unobtrusive Ajax under the NuGet package dependencies says this:

The regex will match both application/javascript and application/x-javascript as will the regex used by the latest jQuery code:

I'm thinking unobtrusive Ajax script should probably use a regex too (the same one jQuery uses, perhaps?); after all, the response content processed might or might not originate from a MVC action returning JavaScriptResult, even when pairing the unobtrusive Ajax script with a JavaScriptResult is the norm.