Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change content-type to text/javascript #223

Open
idleman opened this issue Oct 4, 2019 · 3 comments · May be fixed by #224
Open

Change content-type to text/javascript #223

idleman opened this issue Oct 4, 2019 · 3 comments · May be fixed by #224

Comments

@idleman
Copy link

idleman commented Oct 4, 2019

JavaScript files, such as .js and .mjs should be served with the content-type: "text/javascript" (especially ".mjs" files). The type: "application/javascript" is obsolete.

https://datatracker.ietf.org/doc/draft-ietf-dispatch-javascript-mjs/

The media type registrations herein are divided into two major
categories: the sole media type "text/javascript" which is now in
common usage, and all of the media types that are obsolete.

For both categories, The ECMAScript media types are to be updated to
point to a non-vendor specific standard undated specification of
ECMAScript. In addition, a new file extension of .mjs is to be added
to the list of file extensions with the restriction that it must
correspond to the Module grammar of [ECMA-262]. Finally, the [HTML]
specification is using "text/javascript" as the default media type of
ECMAScript when preparing script tags; therefore, "text/javascript"
has been moved intended usage from OBSOLETE to COMMON.

Chrome enforce this:

To deploy .mjs on the web, your web server needs to be configured to serve files with this extension using the appropriate Content-Type: text/javascript header, as mentioned above. Additionally, you may want to configure your editor to treat .mjs files as .js files to get syntax highlighting. Most modern editors already do this by default.

@mjackson mjackson linked a pull request Oct 7, 2019 that will close this issue
@kevin940726
Copy link

I believe that the link above is still a draft, while the official IETF is still documented to use application/javascript over text/javascript?

@mjackson
Copy link
Owner

mjackson commented Oct 7, 2019

Ya, I think you're right @kevin940726. That's why I didn't merge and just opened the PR. Seems like maybe we should use text/javascript for mjs since it's newer and stick with application/javascript for js files. If anyone stops accepting application/javascript as valid JS, they'll break the web. 😂

@kevin940726
Copy link

@mjackson I like that idea! I think it's the best we can do for now.

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

Successfully merging a pull request may close this issue.

3 participants