Possible Duplicate:
Why write <script type=“text/javascript”> when the mime type is set by the server?
I read Dive into HTML5 a while back, and read its semantics chapter again just recently. I noted it advises not to use type="..." attributes on script and style, because:
- The MIME type should be sent by the server,
- JS and CSS are the defaults,
- Browsers don’t care.
However, I see it is still common practice to include type attributes (or, horror, language) on both script and style tags. Assuming the server is properly configured to send the correct MIME types, are there reasons for using these other than being explicit?
EDIT: This is explicitly about HTML5, not XHTML.
Most people are used to HTML 4/XHTML and before, where the
typeattribute is required for these elements.In regards to HTML 5, these are indeed optional and the spec gives a default, depending on the element.
For the
scripttag, this defaults totext/javascript:For the
styletag, this defaults totext/css:So, not needed, as you stated. However, browser support and server setups can’t always be relied on – being explicit is a good idea as it avoids such problems.
And of course, not all browsers out there support HTML 5 – those that don’t will use an earlier version where the attribute is required and your javascript/css might not get parsed in such browsers, meaning you end up with no CSS or javascript on older browsers, when a simple solution for backwards compatibility is to add the attribute.