简体   繁体   English

资源解释为脚本,但使用MIME类型text / plain传输 - 用于本地文件

[英]Resource interpreted as Script but transferred with MIME type text/plain - for local file

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. 在包含本地脚本文件时,我在Google Chrome中收到“资源解释为脚本但在MIME类型text / plain中传输”警告。

I know the problem appears when loading a file from a server or through ajax which most often depends on wrong headers being set. 我知道从服务器或通过ajax加载文件时出现问题,这通常取决于设置的错误标头。

The weird thing is that I get this warning even though it is run from a local folder: file:///C:/test/foo.html 奇怪的是,即使从本地文件夹运行,我也会收到此警告: file:///C:/test/foo.html

This happens only in Chrome with the most basic html there is: 这种情况仅发生在具有最基本html的Chrome中:

<!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: bar.js也很简单:

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. 并与其他doctypes测试,但似乎没有任何帮助。

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. 这显然不是一个真正的问题,因为脚本仍然可以正常工作,但我正在开发一个大型项目,目前包含大约150个脚本。 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? 关于为什么chrome会让我烦恼的任何想法?

I figured it out! 我想到了!

The Visual Studio installer must have added an errant line to the registry. Visual Studio安装程序必须向注册表添加错误行。

open up regedit and take a look at this registry key: 打开regedit并查看此注册表项:

在此输入图像描述

See that key? 看到那把钥匙? The Content Type key? 内容类型键? change its value from text/plain to text/javascript. 将其值从text / plain更改为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. 我应该注意,Windows 7上默认不存在Content Type和PercievedType,因此您可以安全地删除它们,但您需要做的最小值是编辑。

Anyway I hope this fixes it for you too! 无论如何,我希望这也为你修复它!

I tried fixing this problem using this method but it didn't work for me. 我尝试使用此方法解决此问题,但它对我不起作用。

My problem was that IIS manager didn't have MIME types in HTTP Features. 我的问题是IIS管理器在HTTP功能中没有MIME类型。

I was able to turn it on by enabling Static Context via... 我可以通过启用静态上下文来启用它...

--> Control Panel - >控制面板

--> Programs - >程序

--> Turn Windows features on or off - >打开或关闭Windows功能

--> Internet Information Services - >互联网信息服务

--> World Wide Web Services - >万维网服务

--> Common HTTP features - >常见的HTTP功能

--> [X] Static Content. - > [X]静态内容。

After this, MIME types appeared and everything started working again. 在此之后,MIME类型出现,一切都开始工作了。

The accepted answer is a great one! 接受的答案很棒! However, just to post an answer for those who encounter problem like me, who use a department/college computer sometimes, where I do not have the permission to change any key value in regedit. 但是,只为那些遇到像我这样的问题的人发布答案,有时使用部门/大学的计算机,我没有权限更改注册表中的任何关键值。

Change 更改

<script type="text/javascript" src="main.js"></script>

to

<script src="main.js"></script>

Although the error message still exist, the page loaded correctly. 虽然错误消息仍然存在,但页面加载正确。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Chrome错误-资源被解释为脚本,但以MIME类型的文本/纯文本传输 - Chrome Error - Resource interpreted as Script but transferred with MIME type text/plain js警告:资源被解释为脚本,但以MIME类型text / plain传输 - js warning: Resource interpreted as Script but transferred with MIME type text/plain Chrome表示“资源被解释为脚本,但使用MIME类型的文本/纯文本传输。”,不带服务器 - Chrome says “Resource interpreted as script but transferred with MIME type text/plain.”, without server Cordova插件错误:资源被解释为脚本,但以MIME类型的文本/纯文本传输 - Cordova plugin error: Resource interpreted as Script but transferred with MIME type text/plain 资源被解释为脚本,但以MIME类型text / html javascript传输 - Resource interpreted as Script but transferred with MIME type text/html javascript “资源被解释为脚本,但以MIME类型text / html传输”响应 - 'Resource interpreted as Script but transferred with MIME type text/html' response Rails&Heroku:资源被解释为脚本,但以MIME类型text / html传输 - Rails & Heroku: Resource interpreted as Script but transferred with MIME type text/html ajax错误:资源被解释为脚本,但以MIME类型text / json传输: - ajax error: Resource interpreted as Script but transferred with MIME type text/json: 资源被解释为脚本,但在单个站点上以MIME类型text / html传输 - Resource interpreted as Script but transferred with MIME type text/html on individual site “资源被解释为脚本,但使用MIME类型text / html进行传输。” - “Resource interpreted as script but transferred with MIME type text/html.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM