Should I include type=”text/javascript” in my SCRIPT tags?

You misunderstood what Crockford meant, he didn’t say the type attribute is completely invalid, it’s just that it’s incorrect. The MIME type for JavaScript is application/javascript (or application/ecmascript I can’t remember right now).

The general usage though is that is text/javascript which browsers will handle without any problems as that’s been the defacto standard for a long time.

In regards to the <script src="https://stackoverflow.com/questions/985408/..." tag it is redundant because the server determines the MIME type of the file and that is what the browser will then deal with.

He best explains it in one of his videos on YUI Theater (http://developer.yahoo.com/yui/theater/). I don’t remember exactly which one he talks about this, I think it was in the advanced JavaScript series (but yeah I’ve watched them all a few times so they kind of blur into each other).

So if you want to write valid XHTML you need to provide something like text/javascript but it’s not the official MIME type of the JavaScript language.

Leave a Comment