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

11,235

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. :)
Share:
11,235
S P
Author by

S P

Updated on June 04, 2022

Comments

  • S P
    S P almost 2 years

    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!

  • S P
    S P over 13 years
    The file in question has a .js extension.. Is the script file's header somehow altered by the server, and should I be looking at the server's settings? The file in question is David Desandro's jQuery Masonry script, and I haven't changed it in any way.
  • S P
    S P over 13 years
    It works fine in Safari's webkit implementation... But then, I'm not well-versed in how the implementations differ between the two browsers.
  • Pekka
    Pekka over 13 years
    @Sergio strange. Can you confirm the Content-type header sent for each script file e.g. using Firebug? Other than that, @dekomote's explanation makes sense, but I'd like to see some sources for that before I believe it
  • S P
    S P over 13 years
    Well, strangely enough I'm having trouble in Firefox now too, although it was working fine all morning. I'm pretty sure it is an issue with the server's settings, I'm now getting a 403 Forbidden error for that particular script file. :P Have to leave the computer for now, but thanks for the helpful comments.