I have the following example running without the JS having a bundler on top of it.
// index.js
;(async () => {
const mod = await import('/index.json')
console.log(mod)
})()
{
"file": "index.json"
}
Chrome 80 fails to load the json with
Failed to load module script: The server responded with a non-JavaScript MIME type of "application/json". Strict MIME type checking is enforced for module scripts per HTML spec.
Firefox 73 fails in a similar way:
Loading module from “http://127.0.0.1:8080/index.json” was blocked because of a disallowed MIME type (“application/json”).
Is this behavior surmountable?
text/javascript
, that import would still not work as such in a browser because it is not syntactically valid JavaScript. I suggest you stick withfetch
for the time being.const r = await fetch('/index.json'); const json = await r.json(); const o = JSON.parse(json);
. – Cardcarrying