Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it important to state a MIME type when including a JS file?

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?

like image 989
Tom Avatar asked Nov 04 '22 00:11

Tom


1 Answers

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.

like image 54
cereallarceny Avatar answered Nov 12 '22 16:11

cereallarceny