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

后端 未结 20 2236
眼角桃花
眼角桃花 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 08:08

    If its IIS make sure That Under your common HTTP Features you have Static Content turned on

    0 讨论(0)
  • 2020-11-22 08:08

    In my case, the server was sending the correct Content-Type but with an incorrect Content-Encoding. Make sure that you only set Content-Encoding: gzip for gzipped resources. Also, after I fixed the headers in the server (in my case, Google Cloud Storage), I had to wait a few minutes to properly reflect the changes due to caching.

    0 讨论(0)
  • 2020-11-22 08:11

    Weird issue, but this helped me to solve my issue. Sometimes even the easiest things are hard to figure out...

    Instead of using /js/main.css in my script-tag I used js/main.css

    YES, it did actually make a difference. I'm sitting on WAMP / Windows and I didn't have a vhost but just used localhost/<project>

    If I reference to /js/main.css then I reference to localhost/css/main.css and not to localhost/<project>/css/main.css

    When you think of it, it's quite obvious but if someone stumbles upon this I thought I would share this answer.

    0 讨论(0)
  • 2020-11-22 08:12

    For me, it only happened on some pages because I used window.location instead of $location.url(...); This fixed my problem. Took a while to figure out :)

    0 讨论(0)
  • 2020-11-22 08:12

    A common thing when this happens is if you've simply forgotten to include the type in your script calls. You'll have to set it explicitly, as it is - according to W3 - required:

    type (content-type): This attribute specifies the scripting language of the element's contents and overrides the default scripting language. The scripting language is specified as a content type (e.g., "text/javascript"). Authors must supply a value for this attribute. There is no default value for this attribute.

    Still it seems that browsers have a a default value of plain/text.

    Example:

    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&language=en"></script>
    

    You could as well set a default for that file extension in your Apache configuration:

    <IfModule mod_mime.c>
        AddType text/javascript .js
    </IfModule>
    
    0 讨论(0)
  • 2020-11-22 08:14

    If you are working on Joomla! and getting this annoying error when trying to include a (.js) JavaScript file, then the following solution is for you.

    The most probable problem is that you are trying to include a .js file that isn't there, or you just misplaced that .js file, and when Joomla! doesn't find a resource, then instead of the generic 404 message, it returns a full fledged 404 message with a complete webpage and html etc.

    The web browser is interpreting it as .js whereas its just a webpage saying that the required file wasn't found.

    This can work for joomla2.5joomla3.0joomla3.1joomla3.2joomla3.3joomla

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