0

Possible Duplicate:
HTML Script tag: type or language?

Is there any difference in performance or anything when a web browser encounters

<script language="JavaScript" type="text/javascript">

as opposed to

<script>

They both seem to do the same exact thing.

Community
  • 1
  • 1
node ninja
  • 31,796
  • 59
  • 166
  • 254
  • 1
    The first performs worse because there are more characters to download. The `language` attribute is deprecated. The `type` attribute is requred under the html4 standard though most (all?) browsers seem to cope fine without it. The `type` attribute is optional in html5. – nnnnnn Mar 08 '12 at 23:53
  • I would think that at least the `type` attribute is required by the (X)HTML doctype. – Niko Mar 08 '12 at 23:53
  • 2
    I would refer to [Douglas Crockford](http://javascript.crockford.com/script.html): *`type="text/javascript"` - This attribute is optional. Since Netscape 2, the default programming language in all browsers has been JavaScript. In XHTML, this attribute is required and unnecessary. In HTML, it is better to leave it out. The browser knows what to do.* – Jared Farrish Mar 08 '12 at 23:54
  • 2
    Duplicate: http://stackoverflow.com/q/2267476/1026459 – Travis J Mar 08 '12 at 23:57

2 Answers2

1

The type is a required field per the W3C recommendations: http://www.w3.org/TR/html4/interact/scripts.html

  • 2
    Required for HTML4 and XHTML, but explicitly **not** required for HTML5. – Pointy Mar 08 '12 at 23:59
  • @pointy-but HTML5 isn't a W3C standard. ;-) No one has mentioned that although HTML 4 says type is required, the commonly used value of `text/javascript` is obsolete and `application/javascript` should be used for strict standards compliance. However, using the latter value will cause the script not to be executed in some (perhaps many) browsers. So `text/javascript` continues to be used, breaking one validation requirement to satisfy another. In practice, the type attribute isn't necessary except in very rare cases. – RobG Mar 09 '12 at 00:19
1

In Firefox, language is deprecated (so you shouldn't use it at all) and if you don't specify type, it will be assumed to be JavaScript.

type

This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s src attribute. This is specified as a MIME type; examples of supported MIME types include text/javascript, text/ecmascript, application/javascript, and application/ecmascript. If this attribute is absent, the script is treated as JavaScript.

language Deprecated

Like the type attribute, this attribute identifies the scripting language in use. Unlike the type attribute, however, this attribute’s possible values were never standardized. The type attribute should be used instead.

The recommendation seems to be to include a type, but I doubt it has any performance impact since JavaScript is the only supported type. It's possible that it puts some browsers into quirks mode though, which would be very bad.

Brendan Long
  • 53,280
  • 21
  • 146
  • 188
  • "In Firefox"? In html4 in general... – nnnnnn Mar 09 '12 at 00:07
  • @nnnnnn I used Firefox as an example since it has documentation describing its behavior in this instance. I tried to find something similar for IE but couldn't. – Brendan Long Mar 09 '12 at 00:11
  • Actually the MDN doco you linked to isn't specific to Firefox. It does cover Firefox-specific features, but they will be explicitly marked as such. The "Normative document" links on that page link to the supporting w3c html5 and html4 standards. – nnnnnn Mar 09 '12 at 00:36