0

What content type should I use, if any, in an inline JavaScript block inside HTML?

application/x-javascript
text/javascript

Or something else?

1

4 Answers 4

7

According to the standards you want to use "text/javascript"

Sign up to request clarification or add additional context in comments.

1 Comment

as Gumbo and Chad mentioned, the current recommendation is actually application/javascript; I'd suggest text/javascript for backwards compatibility, though; and btw: I think application/x-javascript is what Apache sends by default for '.js' files...
4

Beside that application/javascript is the official MIME type of JavaScript , most browsers only accept text/javascript or just ignore the type attribute value.

Comments

2

text/javascript

Comments

1

After following a few links through the standards I've come to RFC 4329 which describes Scripting Media Types. It stats that "text/javascript" is obsolete and says that you should now be using "application/javascript".

Edit: Apparently no version of Internet Explorer supports "application/javascript", see: https://connect.microsoft.com/IE/feedback/ViewFeedback.aspx?FeedbackID=338278. So even though "application/javascript" is correct according to the standards, I suppose you need to use text/javascript to compensate for Microsoft's broken browsers (as usual).

1 Comment

Indeed. And in contrast to what the accepted answer says, IE does not ignore an unrecognised type. It refuses to run scripts with application/javascript! So you are forced to use text/javascript, or no type at all. (Note: haven't had a change to test all versions of IE; perhaps the very latest does support application/javascript. But it's best to play it safe; I'm pretty sure all browsers will keep recognising text/javascript for a long time.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.