{"action":"created","issue":{"url":"https://api.github.com/repos/whatwg/html/issues/4211","repository_url":"https://api.github.com/repos/whatwg/html","labels_url":"https://api.github.com/repos/whatwg/html/issues/4211/labels{/name}","comments_url":"https://api.github.com/repos/whatwg/html/issues/4211/comments","events_url":"https://api.github.com/repos/whatwg/html/issues/4211/events","html_url":"https://github.com/whatwg/html/issues/4211","id":385222157,"node_id":"MDU6SXNzdWUzODUyMjIxNTc=","number":4211,"title":"Specify that the single module request sets the Accept header to mime types that are accepted","user":{"login":"andyearnshaw","id":1826067,"node_id":"MDQ6VXNlcjE4MjYwNjc=","avatar_url":"https://avatars3.githubusercontent.com/u/1826067?v=4","gravatar_id":"","url":"https://api.github.com/users/andyearnshaw","html_url":"https://github.com/andyearnshaw","followers_url":"https://api.github.com/users/andyearnshaw/followers","following_url":"https://api.github.com/users/andyearnshaw/following{/other_user}","gists_url":"https://api.github.com/users/andyearnshaw/gists{/gist_id}","starred_url":"https://api.github.com/users/andyearnshaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyearnshaw/subscriptions","organizations_url":"https://api.github.com/users/andyearnshaw/orgs","repos_url":"https://api.github.com/users/andyearnshaw/repos","events_url":"https://api.github.com/users/andyearnshaw/events{/privacy}","received_events_url":"https://api.github.com/users/andyearnshaw/received_events","type":"User","site_admin":false},"labels":[{"id":257427609,"node_id":"MDU6TGFiZWwyNTc0Mjc2MDk=","url":"https://api.github.com/repos/whatwg/html/labels/needs%20implementer%20interest","name":"needs implementer interest","color":"5319e7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-11-28T11:24:17Z","updated_at":"2018-11-29T12:52:52Z","closed_at":null,"author_association":"NONE","body":"In browsers that I've tested (Google Chrome, Safari, Firefox), the following will generate a single network request, with the `Accept` header set to `*/*`:\r\n\r\n```html\r\n<script type=\"module\">\r\n    import '/foo.js';\r\n</script>\r\n```\r\n\r\nThe [*fetch a single module script*](https://html.spec.whatwg.org/multipage/webappapis.html#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](https://github.com/w3c/webcomponents/issues/770) or [WASM](https://github.com/WebAssembly/design/issues/1087) 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. \r\n\r\nStep 9 of the *fetch a single module script* algorithm, which is arrived at after mapping the dependency graph says:\r\n\r\n> If any of the following conditions are met, set moduleMap[url] to null, asynchronously complete this algorithm with null, and abort these steps:\r\n>\r\n> * response's type is \"error\"\r\n> * response's status is not an ok status\r\n> * **The result of extracting a MIME type from response's header list is not a JavaScript MIME type**\r\n\r\nSo, 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](https://mimesniff.spec.whatwg.org/#javascript-mime-type) (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).\r\n\r\nTo 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 file `export default <json>` to all other browsers."},"comment":{"url":"https://api.github.com/repos/whatwg/html/issues/comments/442822835","html_url":"https://github.com/whatwg/html/issues/4211#issuecomment-442822835","issue_url":"https://api.github.com/repos/whatwg/html/issues/4211","id":442822835,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MjgyMjgzNQ==","user":{"login":"andyearnshaw","id":1826067,"node_id":"MDQ6VXNlcjE4MjYwNjc=","avatar_url":"https://avatars3.githubusercontent.com/u/1826067?v=4","gravatar_id":"","url":"https://api.github.com/users/andyearnshaw","html_url":"https://github.com/andyearnshaw","followers_url":"https://api.github.com/users/andyearnshaw/followers","following_url":"https://api.github.com/users/andyearnshaw/following{/other_user}","gists_url":"https://api.github.com/users/andyearnshaw/gists{/gist_id}","starred_url":"https://api.github.com/users/andyearnshaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyearnshaw/subscriptions","organizations_url":"https://api.github.com/users/andyearnshaw/orgs","repos_url":"https://api.github.com/users/andyearnshaw/repos","events_url":"https://api.github.com/users/andyearnshaw/events{/privacy}","received_events_url":"https://api.github.com/users/andyearnshaw/received_events","type":"User","site_admin":false},"created_at":"2018-11-29T12:52:52Z","updated_at":"2018-11-29T12:52:52Z","author_association":"NONE","body":"> It seems that might end up being quite a bit of request bloat though, especially as we get more module types.\r\n\r\nThis did occur to me, especially when I refreshed myself on the list of accepted JavaScript MIME types (which was the reason I suggested the modern subset, e.g. dropping `javascript1.x`, `jscript` and friends) 😕 I guess it could get pretty large if a significant number of module types were added, though I don't know how much of a concern it would be."}}
{"actor":{"display_login":"andyearnshaw"}}