Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I generally include JavaScript files using the script tag as below.

<script type="text/javascript" src="somefile.js"></script>

I have seen some people using the language attribute as well.

Now-a-days I find many people omitting the type attribute. I have started to get a feeling that if JavaScript is the default scripting language then even I should omit the type attribute. Would it be good to omit the type attribute? Would it cause any problems?

share|improve this question

2 Answers 2

up vote 18 down vote accepted

Take a look at this as a reference (Book of Speed): http://www.bookofspeed.com/chapter3.html

Essentially the best way is to combine all your javascript into one file called something like all.min.js that is also minimized.

Typically in HTML5 you would do something like:

<script src="js/all.min.js"></script>

As you can see, you DO NOT need the type attribute in HTML5, but you do in other versions of HTML and XHTML (http://dev.w3.org/html5/spec-author-view/the-script-element.html). The spec clarifies that if the content is other than "text/javascript" then you need to specify the type attribute, in HTML5.

Some things to remember:

  • Always include it before the closing tag. (http://www.yuiblog.com/blog/2008/07/22/non-blocking-scripts/)
  • You should load your scripts in a non-blocking pattern (http://labjs.com/)


If you are going to specify another type other than "text/javascript" you would use one of the following:

  • "application/ecmascript"
  • "application/javascript"
  • "application/x-ecmascript"
  • "application/x-javascript"
  • "text/ecmascript" "text/javascript"
  • "text/javascript1.0"
  • "text/javascript1.1"
  • "text/javascript1.2"
  • "text/javascript1.3"
  • "text/javascript1.4"
  • "text/javascript1.5"
  • "text/jscript"
  • "text/livescript"
  • "text/x-ecmascript"
  • "text/x-javascript"
  • "text/javascript;e4x=1"

The above list is from: http://dev.w3.org/html5/spec-author-view/the-script-element.html#scriptingLanguages

Remember that you would not use the language attribute, only the type attribute.

share|improve this answer
And what about the language attribute. Is it good to specify it or omit it? –  Cracker Jul 9 '11 at 19:41
The language attribute is not supported in HTML5, instead they have merged it with the type attribute. Again, if it is something other than "text/javascript" then you would specify it using the type attribute and one of the following from this page:dev.w3.org/html5/spec-author-view/the-script-element.html –  alvincrespo Jul 9 '11 at 19:47
I've updated the answer to reflect my comment above. –  alvincrespo Jul 9 '11 at 19:51

Just take a look at the w3school. The type attribute is required! Some browser might also treat the scripts based on its extension or mime-type, but I strongly recommend to comply with standards.

share|improve this answer
w3fools.com : the type attribute is not required in HTML5. –  Tom Jul 9 '11 at 16:27
it's not required in HTML4 either; Javascript is the default. –  kevin cline Jul 9 '11 at 21:59
@kevin - Yes, it is required by the 4.01 standard. See w3.org/TR/html401/interact/scripts.html#h-18.2.1 –  kirk.burleson Jul 10 '11 at 1:23
@Kirk: you are correct. As a practical matter, in the absence of any type information, browsers default to Javascript. –  kevin cline Jul 10 '11 at 12:18
@tom Thanks for this! I did not know that w3schools was not affiliated by w3. I won't suggest it to beginners to web anymore! –  crodjer Jul 10 '11 at 12:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.