Chrome says “Resource interpreted as script but transferred with MIME type text/plain.”, what gives?

后端 未结 20 2233
眼角桃花
眼角桃花 2020-11-22 07:21

In FF and all, my javascript works fine. But in Chrome it gives this message:

Resource interpreted as script but transferred with MIME type text/plai

相关标签:
20条回答
  • 2020-11-22 07:51

    If you're generating your javascript with a php file, add this as the beginning of your file:

    <?php Header("Content-Type: application/x-javascript; charset=UTF-8"); ?>
    
    0 讨论(0)
  • 2020-11-22 07:52

    I had this problem while using a web framework and fixed it by moving the relevant javascript files into the designated (by the framework) javascript folder.

    0 讨论(0)
  • 2020-11-22 07:55

    I had this problem and I figured out how to fix it.

    It happens when the style (CSS) file is in a different encoding from the PHP file that references the .css file

    For example, using jQuery.js in Unix encoding and using index.php in UTF-8 will cause this problem so you have to make them both UTF-8 or any other encoding as long as it the same.

    0 讨论(0)
  • 2020-11-22 07:57

    In your apache's httpd.conf, just add such a line:

    AddType application/x-javascript .js
    
    0 讨论(0)
  • 2020-11-22 07:58

    It means that the server is sending a Javascript HTTP response with

    Content-Type: text/plain
    

    You need to configure the server to send a JavaScript response with

    Content-Type: application/javascript
    
    0 讨论(0)
  • 2020-11-22 07:58

    I received this debug message for a sillier reason than the other answers here: This is the error message received when you don't get enough sleep and reference a js file by using the syntax for a css file. As in,

    <link rel='stylesheet' type='text/css' href='clearly_javascript.js'/>
    

    rather than

    <script src='clearly_javascript.js'></script>
    

    Thought I'd put this up here because this is the first post that comes up when searching for the error message.

    0 讨论(0)
提交回复
热议问题