Specify that the single module request sets the Accept header to mime types that are accepted #4211
Labels
needs implementer interest
Moving the issue forward requires implementers to express interest
In browsers that I've tested (Google Chrome, Safari, Firefox), the following will generate a single network request, with the
Accept
header set to*/*
:The fetch a single module script algorithm defines how this request is made, but does not specify that the
Accept
header is set. There are suggestions (external to the HTML spec) to spec imports of types such as JSON or WASM using ES modules. If I'm reading the spec correctly, this would require the implementor to specify custom fetch steps, which would be applied at step 8 of the algorithm. I'm concerned that, once these features make it into browsers, there would be no way to detect them on the server, unless the browser specifies the MIME types it supports as part of the accept header in the request.Step 9 of the fetch a single module script algorithm, which is arrived at after mapping the dependency graph says:
So, since the default fetch algorithm requires a JavaScript MIME type, I think it also makes sense to require that the browser specify JavaScript MIME types (or a modern subset of them) in the
Accept
header. This would mean that, if the browser implements custom fetch steps, they would be required to override this header with something that makes sense instead of deferring to the default*/*
. I fully accept that this would not enforce them to use a list of supported MIME types, but it would encourage it (why would a vendor override the header with*/*
, for instance).To clarify the use case here, let's imagine Firefox adds support for importing JSON data, but other browsers are lagging behind. If the server can reasonably guess (maybe using the referrer) that the request comes from a module, and Firefox sends
Accept: <javascript mime types>, application/json
then a server could detect this and serve the raw file to Firefox whilst serving a wrapped version of the fileexport default <json>
to all other browsers.The text was updated successfully, but these errors were encountered: