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

Use JSON destination for fetching source maps #63

Open
nicolo-ribaudo opened this issue Jan 18, 2024 · 0 comments
Open

Use JSON destination for fetching source maps #63

nicolo-ribaudo opened this issue Jan 18, 2024 · 0 comments

Comments

@nicolo-ribaudo
Copy link
Member

I was working on using fetch to define how source maps are loaded, for #30, and I did some analysis on the current HTTP headers to understand which parameters to pass to fetch.

Firefox devtools:

Headers {
  accept: "*/*",
  "accept-encoding": "gzip, deflate, br",
  "accept-language": "en-US,en;q=0.7,it;q=0.3",
  "cache-control": "max-age=0",
  connection: "keep-alive",
  host: "localhost:4507",
  "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0"
}

Chrome devtools:

Headers {
  "accept-encoding": "gzip, deflate, br",
  "accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
  connection: "keep-alive",
  host: "localhost:4507",
  "sec-fetch-dest": "empty",
  "sec-fetch-mode": "no-cors",
  "sec-fetch-site": "same-origin",
  "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0."... 17 more characters
}

Safari devtools:

Headers {
  accept: "*/*",
  "accept-encoding": "gzip, deflate",
  "accept-language": "en-GB,en;q=0.9",
  connection: "keep-alive",
  host: "localhost:4507",
  referer: "http://localhost:4507/",
  "sec-fetch-dest": "empty",
  "sec-fetch-mode": "no-cors",
  "sec-fetch-site": "same-origin",
  "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17."... 19 more characters
}

I noticed that both Firefox and Safari use Accept: */*, even if the source map is expected to be a JSON file. We recently introduced a "json" fetch destination (https://fetch.spec.whatwg.org/#dom-requestdestination-json) that would have the following effects:

  • Accept is application/json,*/*;q=0.5
  • For browsers that support it, Sec-Fetch-Dest is json

It is currently used by the JSON modules spec import ... with { type: "json" }, but it would fit great for this use case too.

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

No branches or pull requests

1 participant