The "right" type is application/javascript
according to the RFC 4329 (text/javascript
is obsolete). But modern browsers can understand all of them. The reason why "application" is correct is that the browser will run Javascript code, and it does not need to be read (as text) - for example, a minified JS is not readable (in most cases), but can be run smoothly.
In other words, if you want to be exact, and use the recommended MIME type, then you should use application/javascript
. I put the term "correct" above in quotes on purpose - all (as far as I know) modern browsers will treat the response to a request initiated by a <script src=...>
as Javascript, regardless of the content-type value in the server response.
However, it may be that in the future some more strict browser is created, or that some security hole is detected and that makes the browsers require the use of the "correct" mime type, so start using the correct type can now save headache later.
Failure to quote when not specified, having only
<script></script>
– Paulo
@Orion This case is another "war", here I really mean http-headers, then apply tag ;)
– Zuul