-
Notifications
You must be signed in to change notification settings - Fork 43
MIME types #146
Comments
I generally use MIME to disambiguate the format of a given blob that is to be processed. It corresponds to some sort of grammar/evaluation structure for that format. It is generally obtained through file extension or the HTTP
Yes and no, it is a MIME type that is registered for
For However, for
No, it will check the MIME of every dependency and treat them differently according to that.
It doesn't use that string, but I am using the word "MIME" as a means of communicating what format Node is dealing with. In particular, This Per the "why", it is just meaning that some blob being loaded is CJS in format and not something else like JSON.
They absolutely could, and it would make browsers know that the file is not ESM and they would not execute. It also lets things like loaders/service workers/tools/etc. know the format of the file and process it in w/e fashion they need to (such as compiling to a different format).
Yes, but the HTML specification has shown little interest in adding checks so far. This addition would provide a real MIME for the Script goal of JS and means of ensuring something is loaded in the intended format, of which the HTML specification currently doesn't have. It also wouldn't solve the problem for |
Thank you for your answer, it clarified a few things for me.
Is it right to go further and say that in absence of any other information (context, parsing), Thanks for the explanation about To go further:
Thanks, this is the main piece I was missing. While digging into MIME types this morning I found this issue about registring MIME types for Node and the IANA-approved |
Probably can't make any assumption here. Both So... it depends on the environments what I would recommend.
To a browser, Scripts have no associated MIME so it doesn't matter if the web server sends the same MIME as anything else. Effectively, I can't find any browser or web server standard that uses MIMEs and loads using Script.
CJS/ |
To add a bit to what @bmeck wrote, it’s the webservers that choose what MIME type to serve a particular file as, and webservers are free to decide that however they want. Every webserver I’m familiar with chooses MIME types based on file extensions, and they have mappings of what MIME type to choose for each extension, e.g. Node choosing how to parse a file, for example deciding if a The complication for |
The webserver also often needs to know, programmatically (as does many other tools), what it is, so that it can add |
@GeoffreyBooth you can setup custom
Most CDNs also allow uploads directly or through proxying to websites. If they proxy to websites they will use the I do think there is a point of pain here, but it isn't major if Node provides some way to load
However,
Yes, because we don't have another disambiguation mechanism. That is why things like nodejs/node#18392 are attractive and should be looked into. This statement you make is not a point towards wanting ambiguity and wanting the format of a given file to be unable to be known ahead of time, it is just a statement about needing to keep improving our use case satisfaction by having disambiguation be exposed in such a way that people could use |
I am closing this issue because I feel that the MIME types were clarified. You can still comment if you want to. |
I noticed that the IANA draft is still being updated (e.g. https://datatracker.ietf.org/doc/draft-ietf-dispatch-javascript-mjs/ was updated just last week), but the draft makes no mention of the |
@Jessidhia |
I think we were not too concerned about a standards registration for |
@jkrems I don't disagree in a sense of urgency, but I personally want to urge taking a less cut-and-dry view on such matters. When in rome so to speak… JavaScript, MIME, those things come with their own concerns for our consideration, and so we are losing sight of those considerations when we resolve to making concrete what can be fairly just a preference-to-not-bother-yet?! The thing about MIME is that it needs to be distinct today, and tomorrow… and we cannot claim we know how things will look (or how they do already) and so that would be with due respect to the rationale that it is just internal as of yet. Fair to keep in mind that The thing about JavaScript is that it goes places, and one of those is renderers that do consume either formats, and so far that worked without MIME, but no one used MIME back then anyways… this is no longer going to be the case, I mean, if we needed them, they probably will too. All around, not the right time today, but not cut and dry… fair? |
Just to be clear, I think the only update that would potentially need to be done is to update As far as I'm aware there’s no official registration for file extensions: it goes MIME type ➡️ one or more extensions, but not the other way around. |
Update: https://www.iana.org/assignments/media-types/application/node now includes |
Hi,
I want to open an issue dedicated to MIME types. MIME types are mentioned fairly often in the issue #142 but their relevance is not entirely clear for me. Since the other issue is already extremely long, I prefer to open a separate issue.
I would like a clarification about the relation between MIME types, ESM and Node.
Here is what I currently understand, please correct anything wrong and provide more details to clarify the role of MIME types.
.js
istext/javascript
<script src=...>
or<script type="module" src=...>
can be served with any MIME type, browsers don't care:<script src=...>
will use the Script goal,<script type="module" src=...>
will use the Module goal.import
) and treat these dependencies as ESM (even if they are obviously not: exampleapplication/wasm
)application/node
for the script file (for which extensions:.js
,.mjs
,.node
?!). Where is it used? Why? Are servers supposed to serve files with this MIME type?text/javascript
) for both.js
and.mjs
.goal
parameter for the parse goal. So files with the Module goal can be served usingtext/javascript;goal=Module
, files with the script goal can be served with thetext/javascript;goal=Script
MIME type..mjs
to meantext/javascript;goal=Module
goal
MIME parameter currently.goal
parameter is present, the browsers must error if the goal used by the browser does not match the goal served by the server.The text was updated successfully, but these errors were encountered: