pages-gem icon indicating copy to clipboard operation
pages-gem copied to clipboard

WASM served with incorrect MIME type when running locally with jekyll serve

Open Storyyeller opened this issue 5 years ago • 9 comments
trafficstars

I'm trying to use a web assembly (wasm) module, but wasm modules must be served with the content type application/wasm, and when running bundle exec jekyll serve to test the site locally, they are instead served with the content type application/octet-stream used for unrecognized file types. As far as I can tell, this was fixed upstream in Webrick back in 2019, but the github-pages gem is using an outdated version of jekyll which is in turn using an outdated version of webrick that doesn't have the fix.

I tried pushing my changes to github and wasm modules are served with the correct MIME type on a live github pages site. I'm not sure why it works live and is broken locally when the entire point of the github-pages gem is to replicate the same configuration for local testing in order to avoid such issues, but it seems like this can at least be easily fixed by updating the dependencies of the gem.

Storyyeller avatar Jun 21 '20 21:06 Storyyeller

@Storyyeller The list of MIME types supported on GitHub Pages is described here. Unfortunately that does create discrepancies compared to running it locally.

dennispan avatar Jun 22 '20 18:06 dennispan

Link with #651 as this will be resolved if the Jekyll 4.0 is supported

dennispan avatar Jun 22 '20 18:06 dennispan

This is still an issue in Jekyll 4.2. I am having to use my own HTTP server in order to preview gh-pages locally.

Note incorrect content-type here (; charset=utf-8 must not be provided)

dcunnin@dcunnin1:~$ wget -q -S -O /dev/null localhost:8200/js/libjsonnet.wasm HTTP/1.1 200 OK Etag: c10be-65bca7-613285d7 Content-Type: application/wasm; charset=utf-8 Content-Length: 6667431 Last-Modified: Fri, 03 Sep 2021 20:30:15 GMT Cache-Control: private, max-age=0, proxy-revalidate, no-store, no-cache, must-revalidate Server: WEBrick/1.6.1 (Ruby/2.7.4/2021-07-07) Date: Wed, 08 Sep 2021 09:43:49 GMT Connection: Keep-Alive

sparkprime avatar Sep 08 '21 09:09 sparkprime

If anyone knows of a better workaround (e.g. custom mime types using jekyll serve) then please tell me.

sparkprime avatar Sep 08 '21 09:09 sparkprime

Basically in one shell do:

jekyll build --watch

And in another shell, changed to the directory where jekyll builds the website, do:

python3 -c 'import http.server
class Handler(http.server.SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
        self.send_header("Pragma", "no-cache")
        self.send_header("Expires", "0")
        http.server.SimpleHTTPRequestHandler.end_headers(self)


if __name__ == "__main__":
    http.server.test(HandlerClass=Handler)
'

sparkprime avatar Sep 08 '21 10:09 sparkprime

If anyone knows of a better workaround (e.g. custom mime types using jekyll serve) then please tell me.

I just spent several hours trying to monkey-patch Jekyll / WEBrick to set the correct application/wasm Content-Type header on .wasm files. Unfortunately, the internals of Jekyll seem to be just a little too opaque for this to work.

If anyone is curious, I've pushed my attempts on a branch here: https://github.com/alda-lang/alda.io/commit/579235f4cd0925fa4301c5e05951218aa6d8b9bc

For now, as a workaround, I'm giving up on jekyll serve and writing a bin/serve script that does this:

bundle exec jekyll build
npx http-server _site/

It would be nice if I didn't have to resort to all of this hackery, though.

Someone raised this issue with Jekyll 3 years ago: https://github.com/jekyll/jekyll/issues/7743 but it was unfortunately closed as stale after 5 months with no response.

I raised a new issue just now to hopefully get it back onto their radar: https://github.com/jekyll/jekyll/issues/8936

daveyarwood avatar Jan 15 '22 20:01 daveyarwood

It looks like the issue may have been fixed upstream! :tada:

https://github.com/jekyll/jekyll/pull/8965

daveyarwood avatar Feb 25 '22 21:02 daveyarwood

Pages is currently on Jekyll 3.x so I'm going to see if we can backport this into a new release and get Pages to upgrade.

parkr avatar Feb 25 '22 22:02 parkr