Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

actual MIME type and .mjs extension of JavaScript modules ? #7549

Open
bstarynk opened this issue Apr 25, 2019 · 1 comment
Open

actual MIME type and .mjs extension of JavaScript modules ? #7549

bstarynk opened this issue Apr 25, 2019 · 1 comment

Comments

@bstarynk
Copy link

https://developers.google.com/web/fundamentals/primers/modules is mentioning the .mjs extension for JavaScript modules associated to text/javascript MIME type.

On Debian, I submitted the Debian bug#927300 related to that.

I was told that text/javascript is obsolete and it should be application/javascript

I am a web technology newbie.

So what is the preferred MIME type and file extension for JavaScript modules?

Is it text/javascript or application/javascript with .mjs or not?

FWIW, both recent Chrome 74.0.3729 and recent Firefox 60.6 are accepting text/javascript for .mjs JavaScript modules. But I don't know if it is a bug or a feature.

Respectful regards.

Basile Starynkevitch <[email protected]>
http://starynkevitch.net/Basile - Bourg La Reine, France

@GeoffreyBooth
Copy link

The spec says text/javascript: https://html.spec.whatwg.org/multipage/scripting.html#scriptingLanguages:javascript-mime-type

And yes, it is obsolete, or at least it used to be. It’s a head-scratcher why the spec writers chose that MIME type rather than what was the non-deprecated MIME type at the time, application/javascript. So basically both sides are right: you should be using text/javascript, even though it’s obsolete.

The spec, and browsers, don’t care at all about file extensions. You could end your filename with .mjs, with .js, with .foo, or with whatever you want. The file extension is only relevant in that it’s probably what your web server uses to choose what MIME type to serve the file as. As long as it chooses text/javascript, you’re fully compliant.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants