4

I have found myself including more and more external JS files from CDN sites and such. I always see that some sites include the MIME type when you copy the HTML code with the <script> tag and some don't. What is the importance of including the MIME type? Are there browsers that won't support scripts without the MIME type?

Also I've heard that the "official" MIME type for JavaScript is application/javascript but it seems like everyone uses text/javascript. What are the implications of using either one?

Tom
  • 4,422
  • 3
  • 24
  • 36

1 Answers1

2

It's actually not necessary in HTML5 based websites. If you're using the HTML5 doctype of <!DOCTYPE html> then it's not necessary to include a specified type seeing as it's the default now.

With the advent of HTML5, all you need for your script tags is <script src="myScript.js"></script>. If you're interested in more about the differences between application/javascript and text/javascript then check out this post.

Community
  • 1
  • 1
cereallarceny
  • 4,913
  • 4
  • 39
  • 74
  • But what about older browsers? – Tom Apr 12 '13 at 23:19
  • 2
    Depends on how old we are talking about. If you are targeting IE6 then you are likely to get in trouble with it however every other (essentially newer) browser has a fallback mechanism which will treat the lack of `type` attributes correctly. –  Apr 12 '13 at 23:23
  • It depends on your site. If you're programming it as an HTML5 website, then forget about it. If your doctype is one for HTML4 then obviously you should include it. As far as browsers that don't interpret HTML5... well, that depends on the goals for your website. You're the judge. Read up on this article: http://speckyboy.com/2012/03/25/getting-to-grips-with-html5-browser-compatibility/ – cereallarceny Apr 12 '13 at 23:23
  • I'd second what @holodoc said. – cereallarceny Apr 12 '13 at 23:24