3 ms·
Browsers don't look at the file extension, they use Content-Type [0]. To share code between the browser and server you have to update the server config to set
by TheAceOfHearts 8y ago
Browsers don't look at the file extension, they use Content-Type [0].
To share code between the browser and server you have to update the server config to set the Content-Type header to text/javascript when serving .mjs files.
According to the WHATWG HTML spec [1]:
> Servers should use text/javascript for JavaScript resources. Servers should not use other JavaScript MIME types for JavaScript resources, and must not use non-JavaScript MIME types.
Although I'll admit I was surprised to see them suggesting you use text/javascript instead of application/javascript. I've been using application/javascript for years, since I don't have to support old versions of Internet Explorer.
[0] https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_...
[1] https://html.spec.whatwg.org/multipage/scripting.html#scriptingLanguages https://html.spec.whatwg.org/multipage/scripting.html#script...