Serving mjs files with nginx
Avishkar Autar · Apr 23 2020 · Web Technologies
In my previous post on ES modules, I mentioned adopting the mjs file extension for modules files. Unfortunately, there’s no entry for the mjs extension in nginx’s default mime.types file, meaning it’ll be served as application/octet-stream
instead of application/javascript
. The MIME type for mjs files can be set by explicitly including mime.types in a server, http, or location block & adding a types block with the MIME type and file extension:
server
{
include mime.types;
types
{
application/javascript mjs;
}
...
}
Maybe it’s not all systems, but when it’s modified like this…you may need to add js to that line right next to mjs
types
{
application/javascript js mjs;
}