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!
5 Answers
Reset to default 1Without 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条)