<script type="text/javascript">
/* ... */
</script>
vs.
<script language="Javascript">
/* ... */
</script>
Which should be used and why?
Or, the third alternative: omitting either of these, such as the example code in jQuery’s API reference:
<script src="http://code.jquery.com/jquery-latest.js"></script>
The
languageattribute has been deprecated for a long time, and should not be used.When W3C was working on HTML5, they discovered all browsers have “text/javascript” as the default script
type, so they standardized it to be the default value. Hence, you don’t needtypeeither.For pages in XHTML 1.0 or HTML 4.01 omitting
typeis considered invalid. Try validating the following:You will be informed of the following error:
So if you’re a fan of standards, use it. It should have no practical effect, but, when in doubt, may as well go by the spec.