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

wrong MIME typ "text/plain" for .js files #241

Closed
blaboing opened this issue Feb 3, 2022 · 10 comments
Closed

wrong MIME typ "text/plain" for .js files #241

blaboing opened this issue Feb 3, 2022 · 10 comments
Labels
bug Something isn't working

Comments

@blaboing
Copy link

blaboing commented Feb 3, 2022

4.5.0 release (win) serves js files with wrong MIME typ "text/plain" so they aren´t loaded and the page is stuck at "Starting mapserver..."

@BuckarooBanzay BuckarooBanzay added the bug Something isn't working label Feb 3, 2022
@BuckarooBanzay
Copy link
Member

Are you sure they are sent with text/plain? i can't reproduce that locally:

$ curl -v http://127.0.0.1:8080/js/bundle.js | head
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /js/bundle.js HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Length: 66757
< Content-Type: application/javascript
< Date: Thu, 03 Feb 2022 12:14:44 GMT
< 

@blaboing
Copy link
Author

blaboing commented Feb 3, 2022

Yes Firefox web console reported that.

13:41:03.173 The script from “http://127.0.0.1:8080/js/lib/mithril.min.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type. 127.0.0.1:8080
13:41:03.174 The script from “http://127.0.0.1:8080/js/lib/leaflet.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type. 127.0.0.1:8080
13:41:03.174 The script from “http://127.0.0.1:8080/js/lib/leaflet.awesome-markers.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type. 127.0.0.1:8080
13:41:03.176 The script from “http://127.0.0.1:8080/js/bootstrap.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type. 127.0.0.1:8080
13:41:03.177 The script from “http://127.0.0.1:8080/js/lib/moment.min.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type. 127.0.0.1:8080
13:41:03.346 Loading failed for the module with source “http://127.0.0.1:8080/js/main.js”. 127.0.0.1:8080:1:1
13:41:03.350 Loading module from “http://127.0.0.1:8080/js/main.js” was blocked because of a disallowed MIME type (“text/plain”). 127.0.0.1:8080

@BuckarooBanzay
Copy link
Member

Looks like a windows-issue, pretty strange though.
Can you give me the following info:

  • The actual content of http://127.0.0.1:8080/js/bootstrap.js if you enter it in the browser-url for example
  • What happens when you access it through http://localhost:8080 (it goes into web-dev mode if the website-url is "127.0.0.1")

@blaboing
Copy link
Author

blaboing commented Feb 3, 2022

bootstrap.js

(function(){
  var s = document.createElement("script");

  if (location.host === "127.0.0.1:8080") {
    //dev
    s.setAttribute("src", "js/main.js");
    s.setAttribute("type", "module");

  } else {
    //prod
    s.setAttribute("src", "js/bundle.js");

  }

  document.body.appendChild(s);
})();

and map loads perfectly with localhost

@BuckarooBanzay
Copy link
Member

looks like an issue with the golang+windows combination: golang/go#32350 (some 3rd-party app changes the registry keys 😕)

@blaboing
Copy link
Author

blaboing commented Feb 4, 2022

yep my registry returns "text/plain".
Interesting that it is handled differently somewhere for 127.0.0.1 and localhost.
I´m good with using localhost but maybe add a hint to documentation.

@S-S-X
Copy link

S-S-X commented Feb 4, 2022

So, what causes it to work with localhost is actually go bug... and failing with 127.0.0.1 is documented feature... interesting 🤔

@BuckarooBanzay
Copy link
Member

BuckarooBanzay commented Feb 5, 2022

So, what causes it to work with localhost is actually go bug... and failing with 127.0.0.1 is documented feature... interesting thinking

This has to do how the differentiation between dev and release is (was) made:

var s = document.createElement("script");
if (location.host === "127.0.0.1:8080") {
//dev
s.setAttribute("src", "js/main.js");
s.setAttribute("type", "module");
} else {
//prod
s.setAttribute("src", "js/bundle.js");
}
document.body.appendChild(s);

Basically: use the "module" script files only if the browser calls the app with "127.0.0.1:8080"
Background is that there is a more efficient (only one http-call) release "bundle.js" that should be used instead of the various other .js modules when developing.

I overhauled the bootstrap logic for this now:

<script>
function dev_fallback(){
var s = document.createElement("script");
s.setAttribute("src", "js/main.js");
s.setAttribute("type", "module");
document.body.appendChild(s);
};
</script>
<script src="js/bundle.js" onerror="dev_fallback()"></script>

This tries to load the bundle first and falls back to the dev-files if it isn't available (not generated/not a release-build for example)

Anyway: the mime-type issue isn't fixed with this, i think i'll just hardcode the main mime-types for .js/.css and .html shouldn't really hurt i guess 🤷

@blaboing
Copy link
Author

blaboing commented Feb 7, 2022

Just tried it and now 127.0.0.1 and localhost work fine.
Both still report that the js files are served as "text/plain" but loading isnt blocked anymore.

@BuckarooBanzay
Copy link
Member

fixed with golang/go#32350

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants