Can "text/javascript" be assumed a de facto default for the <script> element?
Despite that the HTML4 standard states there is no default for the <script>
element, looks like browsers assume "text/javascript" by default. How safe is this assumption?
To Standards Nazis: I know this is something to raise an eyebrow upon, but I believe there is no开发者_Python百科thing wrong in exploiting some de facto standards for the sake of readability and succinctness (e.g. omitting quotes around simple attribute values, etc).
As of HTML5 then text/javascript
is the standard when no type
is specified.
Personally however, I'd be inclined to always specify type
- better safe than sorry!
Additionally, I'd always advise writing code under the assumption that someone else will have to support it. Do you think the next person along will thank you for your 'time-saving' solutions that make the code harder to follow? I very much doubt it ;)
HTML5 now doesn't require the mimetype to be declared in a script tag, as "text/javascript" is implied; so yes, I think it's safe to assume that this is the default.
From experience i know that it isn't safe to make this assumption.
However, the HTML5 standard does describe this standard value for the language attribute being "text/javascript".
精彩评论