Search code examples
javascriptecmascript-6mime-typeses6-modules

JavaScript ES6 Modules MIME Type


What is the right (or better) MIME Type for JavaScript ES6 modules (*.mjs): text/javascript, application/javascript or javascript/esm?


Solution

  • text/javascript is the correct JavaScript MIME type per the HTML Standard, which states:

    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.

    And also:

    […] the MIME type used to refer to JavaScript in this specification is text/javascript, since that is the most commonly used type, despite it being an officially obsoleted type according to RFC 4329.

    Work is underway to reflect this reality in an RFC at the IETF level: https://datatracker.ietf.org/doc/draft-ietf-dispatch-javascript-mjs/