Chrome says “Resource interpreted as script but tr

2018-12-31 09:50发布

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/plain.

I have checked all the script tags and they all have the MIME type="text/javascript". It even says so with jquery and jquery ui. What is wrong with Chrome?

What's the problem and the fix for this? Is it something I have to change in the 'options' of the browser or is it from the server, or do I have to tweak my code?

20条回答
刘海飞了
2楼-- · 2018-12-31 10:05

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

AddType application/x-javascript .js
查看更多
闭嘴吧你
3楼-- · 2018-12-31 10:05

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.

查看更多
忆尘夕之涩
4楼-- · 2018-12-31 10:07

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.

查看更多
姐姐魅力值爆表
5楼-- · 2018-12-31 10:07

If you are using AdonisJS (REST API, for instance), one way to avoid this is to define the response header this way:

response.safeHeader('Content-type', 'application/json')
查看更多
与风俱净
6楼-- · 2018-12-31 10:08

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 :)

查看更多
呛了眼睛熬了心
7楼-- · 2018-12-31 10:09

The answer posted here by simon-sarris helped me.

This helped me solve my issue.

The Visual Studio installer must have added an errant line to the registry.

open up regedit and take a look at this registry key:

enter image description here

See that key? The Content Type key? change its value from text/plain to text/javascript.

Finally chrome can breathe easy again.

I should note that neither Content Type nor PercievedType are there by default on Windows 7, so you could probably safely delete them both, but the minimum you need to do is that edit.

Anyway I hope this fixes it for you too!

Don't forget to restart your system after the changes.

查看更多
登录 后发表回答