2

I know this has been asked many many times, but on MDN it states that the correct MIME type to serve javascript as is text/javascript, and all other MIME types are depreciated contradicting most answers such as this or this.

What MIME type should I use when serving javascript content?

7
  • 4
    Possible duplicate of text/javascript vs application/javascript Commented Dec 14, 2018 at 22:12
  • Possible duplicate of what is difference between text/javascript and application/javascript Commented Dec 14, 2018 at 22:15
  • Neither. There is absolutely no need to specify a mime type on a script tag. Commented Dec 14, 2018 at 22:15
  • @JaredSmith You are right on the script tag but the mime type is still relevant for setting the corret Content-Type header on the response from the web server. Commented Dec 14, 2018 at 22:17
  • @Karl-JohanSjögren very, very true, but since it wasn't tagged node.js and the general tenor of the question I assumed script tag. Commented Dec 14, 2018 at 22:23

1 Answer 1

7

The MDN article links to the WHATWG (Web Hypertext Application Technology Working Group, which consists of people from Apple, Google, Mozilla, Microsoft and others) HTML Living Standard that was last updated a few days ago. This is the current most up to date HTML specification and it says text/javascript.

Servers should use text/javascript for JavaScript resources. Servers should not use other JavaScript MIME types for JavaScript resources, and must not use non-JavaScript MIME types.

In reality though no browser will break on either text/javascript or application/javascript so it doesn't really matter. For new projects I would definitely use text/javascript but I won't go back and update my old ones.

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

Comments

Your Answer

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