javascript - Why might Chrome return an incorrect MIME type error for one of my JS files when they are all served the same way?

I'm getting an error reading one of my JavaScript files ("Resource interpreted as script but

I'm getting an error reading one of my JavaScript files ("Resource interpreted as script but transferred with MIME type text/html.") from Google Chrome. The other three JS files that my page calls load just fine, and I'm confused about what is causing this problem since they are all marked up in exactly the same way (and each has a "type=text/javascript" attribute). Safari and Firefox both have no problem reading all four JS files. Can anyone give me a tip on how to troubleshoot this properly? Thanks for any help!

I'm getting an error reading one of my JavaScript files ("Resource interpreted as script but transferred with MIME type text/html.") from Google Chrome. The other three JS files that my page calls load just fine, and I'm confused about what is causing this problem since they are all marked up in exactly the same way (and each has a "type=text/javascript" attribute). Safari and Firefox both have no problem reading all four JS files. Can anyone give me a tip on how to troubleshoot this properly? Thanks for any help!

Share Improve this question asked Sep 18, 2010 at 21:04 S PS P 2411 gold badge4 silver badges8 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 1

Without going any further, this error what it tells us is that we are sending JS code as plain text rather than sending the header as a script.

This is and happens because we define the tag as an attribute <script type="text/javascript">, when we should put <script type="application/x-javascript">.

Incorrect example:

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

Correct example:

<script type="application/x-javascript" src="js/utils.js"></ script>

Then Google Chrome will understand it.

                                                                      Jordi. :)

It looks like one of your JavaScript files is not being sent with the correct Content-type header. The type attribute specified in the script tag won't have an effect here - it's the script file's header that counts.

My guess would be it has a non-standard extension (e.g. .php or .asp) that causes your server to send a different MIME type that that for .js files.

I think that this is a webkit bug. I don't think you can troubleshoot this.

try using proper content type in the page which actually refer the script.

Something like

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-strict.dtd">

and then start your HTML with

<html xmlns="http://www.w3/1999/xhtml">

PS: the magic is in the "strict" :)

Check to make sure that the file actually exists too. In FireFox it will report that it was loaded even when the file doesn't even exists.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744161481a4561111.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信