简体   繁体   中英

Javascript MIME Type not Set Properly

I'm building some web apps with Python/Tornado.

Some of my (HTML) pages have:

<script src="/static/some_script.js" type="text/javascript"></script>

When I load the page in FireFox, I get the warning:

"The script from “http://localhost:8086/static/some_script.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type."

Why does the browser think the MIME type is "text/plain" instead of "text/javascript"? Where is it getting that idea from....?

I also load:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

and

<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js" type="text/javascript"></script>

for which I don't get the same warning.....

Mime type is something the server send as header detail and it's usually based on file extension, but it can be enforced as needed.

If you run your Web page/application locally, you need to spin a webserver for that folder, as opening the .html file directly will not work, or better, requested files will not be served with the correct mime type.

Use a webserver, and you'll never see this error again.

I had the same problem but with ExpressJS application. For me, path to the concerned static file was not correct. So exressjs(web server) defaulted to text/html mime type.

so check if "/static/some_script.js" path is correctly directing to the static file (some_script.js)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM