When I add JavaScript files to web pages, I have always done for example like this:
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript">
// Custom script
</script>
But today I discovered in the response headers that JavaScript are actually served as application/javascript
. Why is that? Is both correct? Or should I change one to the other? What's going on here?
When I add JavaScript files to web pages, I have always done for example like this:
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript">
// Custom script
</script>
But today I discovered in the response headers that JavaScript are actually served as application/javascript
. Why is that? Is both correct? Or should I change one to the other? What's going on here?
- I think that this one explains it good: annevankesteren.nl/2006/05/javascript-mime-type – Tomasz Kowalczyk Commented Sep 13, 2010 at 11:16
- 2 Also see Why write <script type=“text/javascript”> when the mime type is set by the server? – Marcel Korpel Commented Sep 13, 2010 at 11:52
- Well, it explained that application/javascript was the one I should use. But not which one I should use... Also its from 2006. So is it still the case that I should use text/javascript because of browsers, or? – Svish Commented Sep 13, 2010 at 11:54
-
@Svish: At least IE 7 (and 8?) does have problems with
script
elements with MIME-type set toapplication/javascript
, and as there are still plenty IE users out there… – Marcel Korpel Commented Sep 13, 2010 at 12:39 - Well, link appears to be broken. Good answer should link to original sources, but also refer most important contents briefly - just because this happens all the time. – Olli Commented Aug 29, 2012 at 8:15
1 Answer
Reset to default 2with HTML5, you can just omit the type attribute pletely. All browsers assume a default type of JavaScript.