8

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?

7
  • I think that this one explains it good: annevankesteren.nl/2006/05/javascript-mime-type 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? 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? Commented Sep 13, 2010 at 11:54
  • @Svish: At least IE 7 (and 8?) does have problems with script elements with MIME-type set to application/javascript, and as there are still plenty IE users out there… 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. Commented Aug 29, 2012 at 8:15

1 Answer 1

2

with HTML5, you can just omit the type attribute completely. All browsers assume a default type of JavaScript.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.