资源解释为脚本,但是以MIME类型text / plain传输 - 用于本地文件 [英] Resource interpreted as Script but transferred with MIME type text/plain - for local file

查看:825
本文介绍了资源解释为脚本,但是以MIME类型text / plain传输 - 用于本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我知道在Chrome浏览器中有一个资源解释为脚本,但是通过MIME类型text / plain传输警告。从服务器或通过ajax加载文件时出现的问题通常取决于设置了错误的标题。



奇怪的是,即使它出现此警告从本地文件夹运行: file:/// C:/test/foo.html



发生这种情况只有在使用最基本的html的Chrome才有:

 <!DOCTYPE html> 
< html>
< head>
< script type =text / javascriptsrc =bar.js>< / script>
< / head>
< body>
< / body>
< / html>

bar.js也是如此简单:

 函数hello(){} 

我尝试添加元标记:

 < meta http-equiv =content-script-typecontent =文本/ JavaScript的> 

并与其他doctypes进行了测试,但没有任何帮助。



这显然不是一个真正的问题,因为脚本仍然可以正常工作,但我正在开发一个大型项目,目前包含大约150个脚本。因此,它很难看到它们之间发生实际警告的时间。



当我在本地或远程服务器上运行文件时,一切正常。



任何关于为什么chrome会令我恼火的想法? 它出来!

Visual Studio安装程序必须添加一个错误行到注册表。



开放 regedit 并查看此注册表项:



看到这个关键?内容类型密钥? 将其值从文本/纯文本更改为文本/ javascript。



最后,chrome可以轻松呼吸。



我应该注意的是,在Windows 7上默认情况下,Content Type和PercievedType都不存在,所以您可以安全地将它们都删除,但您需要做的最低限度是编辑。



无论如何,我希望这能为您解决它!


I'm getting a "Resource interpreted as Script but transferred with MIME type text/plain" warning in Google Chrome when including a local script file.

I know the problem appears when loading a file from a server or through ajax which most often depends on wrong headers being set.

The weird thing is that I get this warning even though it is run from a local folder: file:///C:/test/foo.html

This happens only in Chrome with the most basic html there is:

<!DOCTYPE html>
    <html>
    <head>
        <script type="text/javascript" src="bar.js"></script>
    </head>
    <body>
    </body>
</html>

bar.js is also as simple as it can get:

function hello() {}

I've tried adding a meta tag:

<meta http-equiv="content-script-type" content="text/javascript">

and tested with other doctypes but nothing seems to help.

This obviously isn't a real issue since the scripts still work fine, but I'm working on a large project and currently have around 150 scripts included. It therefore makes it difficult to see when an actual warning occurs in between them.

Everything works fine when I run the file on a server, locally or remote.

Any ideas on why chrome is annoying me with this?

解决方案

I figured it out!

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

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

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!

这篇关于资源解释为脚本,但是以MIME类型text / plain传输 - 用于本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆