Most of the script tags I create, I always include type="text/javascript" language="javascript"
in the tag. My boss however does not. Sometimes he excludes both, sometimes just has language=javascript
even without the quotes
Now we have not had an issue in any of the major browsers with his tags. I'm talking about all versions of IE, FF, Safari, and Chrome.
Personally I feel it's laziness and just totally improper and bad coding practice to leave stuff out like this even if it works without it.
Anyone know if both should be included or just one or is it ok to leave both out in ASP.NET?
The type attribute in JavaScript is optional since the introduction of HTML5 brought some new improvements. JavaScript became the default language for HTML5 and modern browsers. So, now adding text/javascript isn't required in <script> tag.
What is JavaScript? JavaScript (often shortened to JS) is a lightweight, interpreted, object-oriented language with first-class functions, and is best known as the scripting language for Web pages, but it's used in many non-browser environments as well.
These days, most cross-browser JavaScript problems are seen: When poor-quality browser-sniffing code, feature-detection code, and vendor prefix usage block browsers from running code they could otherwise use just fine. When developers make use of new/nascent JavaScript features, modern Web APIs, etc.)
The <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute.
I suppose this should be updated now that the landscape has changed quite a bit:
For an HTML5 doctype, it's no longer required. For example: we leave it out of the pages here at Stack Overflow. If you're using an HTML5 doctype then it's completely optional and defaults to text/javascript
, so you're absolutely fine leaving it off in every current (or even very old) browser. Realistically, this was also true even in HTML4 though not strictly valid HTML.
For an HTML4 doctype (to be valid), you need it. For a browser to actually function, it's not strictly needed and will behave just fine (this has been true all the way back to Netscape 2) - but it won't be valid HTML. If you have an HTML4 doctype, then keep it around and be valid - cause hey, why not?
Original Answer:
I would use type="text/javascript"
to be safe in all current browsers, why leave the ambiguity in there to save 21 characters? language=""
however is deprecated, I'd leave it out.
Also, any validator is going to throw an error, though it will likely work inside the browser (unless you're dealing with something very old).
According to the w3c spec, type
is required. So... even though most browsers are going to be robust enough to work without type
being properly specified, it is good practice to explicitly set it to text/javascript
.
The W3C recommendation for HTML5 says that you do not need to include:
type="text/javascript"
The browser assumes that it is text/javascript
unless otherwise stated as a different type.
http://dev.w3.org/html5/spec/Overview.html#the-script-block-s-type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With