• Publisert
  • 1 min

Does your script need a type?

Many years after HTML 5 became the HTML of choice, the type of a script element is still being specified. Stop it!

One of my (admittedly ridiculously unimportant) pet peeves with HTML being created today is the following:

<script type="text/javascript">
[…]
</script>

I see this all the time, on almost all web sites, even with the most up-to-date, modern CMS.

(Yup, you'll even find it in the source code of this very blog post. Thanks a lot, Disqus integration for Episerver.)

Allow me to quote the venerable Douglas Crockford to point out how pointless specifying the type attribute on a script element is these days:

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.

Since 1995, your browser will have understood perfectly fine what to do without specifying the type attribute.

During the time of HTML 4 and XHTML 1, this attribute was required for validating your HTML. Yet, we aren't writing HTML 4 and XHTML 1 anymore, are we?

You might as well be writing <font> in your HTML.

So, please stop.

If it's JavaScript, you don't need to specify the type attribute on a script element. Even Internet Explorer 3 understands.

Also, you don't need to use CDATA sections or HTML comments inside your script tags.

Embrace the simpler side of HTML 5, keep your script tags to a minimum.