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

net/http: add built-in mime type for *.mjs #30547

Open
dkumor opened this Issue Mar 3, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@dkumor
Copy link

dkumor commented Mar 3, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/daniel/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/daniel/.go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build067538039=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Given a folder with the following files:

index.html:

<html>
<body>
<script type="module" src="test.mjs"></script>
</body>
</html>

and test.mjs (see: https://developers.google.com/web/fundamentals/primers/modules)

console.log("hi!");

My code serves the above with http.FileServer, and I navigate to / in my browser, opening index.html

What did you expect to see?

I expected hi to be printed in the javascript console

What did you see instead?

The following error in chrome:

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.

This is because .mjs is not a recognized mimetype. This can easily be worked around by manually adding .mjs to the mime database:

mime.AddExtensionType(".mjs", "application/javascript")

Or, technically, one can just use .js - but .mjs seems to be commonly used.

However, since es modules are a standard, and will become more common in the future, it would be nice to have the mimetype built in.

@bradfitz bradfitz changed the title es modules mjs extension in http.FileServer net/http: add built-in mime type for *.mjs Mar 5, 2019

@bradfitz

This comment has been minimized.

Copy link
Member

bradfitz commented Mar 5, 2019

Is there an official spec that's proposing standardizing that mime type for that extension? (something more formal that the page you linked)

@dkumor

This comment has been minimized.

Copy link
Author

dkumor commented Mar 5, 2019

That's a good question.

Mime

mjs Extension

I did not find anything "official", other than common usage:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.