简体   繁体   English

Chrome错误-资源被解释为脚本,但以MIME类型的文本/纯文本传输

[英]Chrome Error - Resource interpreted as Script but transferred with MIME type text/plain

I have tried ALL the solutions on many pages with no success. 我在许多页面上尝试了所有解决方案,但均未成功。 I did not have Visual Studio installed so no registry tweaks needed there. 我没有安装Visual Studio,因此不需要在那里进行注册表调整。 Adding in header tags into PHP did not work for me. 在PHP中添加标头标记对我不起作用。 It seemed it was affecting my .css files and also my .js files. 似乎它正在影响我的.css文件以及我的.js文件。 Firefox would only show the .css errors and also show NO style rules at all. Firefox只会显示.css错误,也不会显示任何样式规则。

The exact errors are... 确切的错误是...

Resource interpreted as Stylesheet but transferred with MIME type text/html: " http://newpcs.perrycs.com/css/bootstrap-theme-cerulean.css ". 资源被解释为样式表,但以MIME类型text / html传输:“ http://newpcs.perrycs.com/css/bootstrap-theme-cerulean.css ”。

and

Resource interpreted as Script but transferred with MIME type text/html: " http://newpcs.perrycs.com/js/bootstrap.js ". 资源被解释为脚本,但以MIME类型text / html传输:“ http://newpcs.perrycs.com/js/bootstrap.js ”。

UPDATE: I found a fix from my web host IT. 更新:我从网络托管IT找到了修复程序。 They said to add the following code to my .htaccess file and it DID solve the .css but not the .js in Chrome. 他们说要将以下代码添加到我的.htaccess文件中,它会DID解决Chrome中的.css而不是.js问题。 Here is the code they had me put in... 这是他们让我输入的代码...

Options -Indexes

<FilesMatch "(\.css)$"> 
   AddType text/css .css 
   Header set Content-Type text/css 
</FilesMatch>

AddType application/x-javascript .js

It fixed it for the .css but not the .js 它修复了.css而不是.js的问题

I have also tried... 我也尝试过...

AddType application/javascript .js

with no luck. 没有运气。 I"m waiting to hear back from IT again but in the meantime I'll keep looking. I know the .js works.. it's just an OCD thing ... I don't want ANY errors in Chrome. 我正等待再次收到IT人士的回覆,但与此同时,我将继续寻找。我知道.js可以工作。.这只是OCD的事情...我不希望Chrome中出现任何错误。

Can you please try: 您可以尝试:

AddType application/javascript *.js

I feel that the * might help. 我认为*可能会有所帮助。


Might redeclaring the same thing of CSS for JS would help? 可能会为CSS重新声明CSS的相同内容会有所帮助吗?

<FilesMatch "(\.js)$"> 
   AddType application/javascript .js
   Header set Content-Type application/javascript 
</FilesMatch>

if the CSS rule works, you could replicate it for JavaScript: 如果CSS规则有效,则可以将其复制为JavaScript:

<FilesMatch "(\.js)$"> 
   AddType application/javascript .js 
   Header set Content-Type application/javascript
</FilesMatch>

While I was waiting to get help from IT. 在等待获得IT帮助时。 I previously asked them... should I do the same with the .js as with the .css and I was told NO... the only thing you need for .js is 之前我问过他们...我应该对.js和.css做同样的事吗?我被告知否...对.js唯一需要的是

AddType application/x-javascript .js

That's what they gave me... and it did NOT solve my problem. 那就是他们给我的……但并不能解决我的问题。 I also tried... 我也尝试过...

AddType application/javascript .js

and that did NOT work as well. 而且效果不佳。

So... I thought I would try the thing I was told not to try. 所以...我以为我会尝试告诉我不要尝试的事情。 Here is my final .htaccess file. 这是我最后的.htaccess文件。

Options -Indexes

<FilesMatch "(\.css)$"> 
   AddType text/css .css 
   Header set Content-Type text/css 
</FilesMatch>

<FilesMatch "(\.js)$"> 
   AddType application/javascript .js
   Header set Content-Type application/javascript 
</FilesMatch>

and... it WORKS! 而且...有效! No more errors in Chrome. Chrome中没有更多错误。 I have no idea about .htaccess files... I thought... well, it didn't work with the .js after all... so what harm can come from this? 我对.htaccess文件一无所知...我以为...好吧,它毕竟无法与.js一起使用...所以这可能带来什么危害? Anyone want to help me out and tell me that what I have done is a bad thing? 任何人都想帮助我并告诉我我所做的事情是一件坏事吗? Any bad side effects? 有不良副作用吗?

I should also note... there was never a problem in the past with my .css files or my .js files. 我还应该注意...过去,我的.css文件或.js文件从来没有问题。 It seems to have happened after they upgraded something but I do not know for sure as I wasn't looking into the problem right when I noticed my CSS styles disappeared from my side projects. 他们升级某些东西后似乎发生了这种情况,但是我不确定,因为当我发现我的CSS样式从我的辅助项目中消失时,我没有在研究问题。 Well, as long as it works... 好吧,只要它能起作用...

Oh man, they are trolling you !!! 哦,老兄,他们在骗你! This is a very simple case, no alteration of .htaccess is needed. 这是一个非常简单的情况,不需要更改.htaccess。

Its about the file format. 关于文件格式。 I dont mean the extension, but the way u created the file. 我的意思不是扩展名,而是您创建文件的方式。

For example: If you get the error on a linux server, i bet you created that file inside of windows explorer or kinda. 例如:如果您在Linux服务器上收到错误,我敢打赌您是在Windows资源管理器或同类中创建该文件的。

The solution is to open the file in notepad++ and goto menu "coding". 解决方案是在notepad ++中打开文件,然后转到菜单“编码”。 No u have to know which charset is selected for your webserver. 您不必知道为您的Web服务器选择了哪个字符集。 They have to match (fileformat-serverformat) Now u select "Convert into [yourformat]", for me its "UTF8 wo BOM". 它们必须匹配(fileformat-serverformat),现在,选择“转换为[yourformat]”,对我来说是“ UTF8 wo BOM”。

Backup your files before u try this. 尝试之前,请备份文件。

暂无
暂无

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

相关问题 js警告:资源被解释为脚本,但以MIME类型text / plain传输 - js warning: Resource interpreted as Script but transferred with MIME type text/plain 资源解释为脚本,但使用MIME类型text / plain传输 - 用于本地文件 - Resource interpreted as Script but transferred with MIME type text/plain - for local file 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 ajax错误:资源被解释为脚本,但以MIME类型text / json传输: - ajax error: Resource interpreted as Script but transferred with MIME type text/json: 返回json时,Chrome扩展程序错误:资源被解释为脚本,但以MIME类型text / json传输 - Chrome Extension error when returning json: Resource interpreted as Script but transferred with MIME type text/json 链接的样式表错误-资源被解释为样式表,但以MIME类型文本/纯文本传输 - Linked Stylesheet Error - Resource interpreted as Stylesheet but transferred with MIME type text/plain Chrome说“资源解释为样式表,但使用MIME类型text / html传输” - Chrome says “Resource interpreted as Stylesheet but transferred with MIME type text/html” 资源被解释为脚本,但以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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM