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?

  • 3
    Possible duplicate of [text/javascript vs application/javascript](https://stackoverflow.com/questions/21098865/text-javascript-vs-application-javascript) – Devinder Dec 14 '18 at 22:12
  • Possible duplicate of [what is difference between text/javascript and application/javascript](https://stackoverflow.com/questions/6122905/what-is-difference-between-text-javascript-and-application-javascript) – Falcon Dec 14 '18 at 22:15
  • Neither. There is absolutely no need to specify a mime type on a script tag. – Jared Smith Dec 14 '18 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. – Karl-Johan Sjögren Dec 14 '18 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. – Jared Smith Dec 14 '18 at 22:23
  • Possible duplicate of [When serving JavaScript files, is it better to use the application/javascript or application/x-javascript](https://stackoverflow.com/questions/876561/when-serving-javascript-files-is-it-better-to-use-the-application-javascript-or) – Herohtar Dec 14 '18 at 22:32
  • @Jared Smith Ah sorry, i meant what mime type should i use when sending content, i will update to clarify –  Dec 14 '18 at 23:09

1 Answers1

4

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.

Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68