简体   繁体   English

资源被解释为样式表,但使用 MIME 类型 text/javascript 传输

[英]Resource interpreted as Stylesheet but transferred with MIME type text/javascript

I have created an application using MVC, Java Script, JQuery, Ajax.我使用 MVC、Java Script、JQuery、Ajax 创建了一个应用程序。 When I'm debugging using visual studio it works fine without any script errors.当我使用 Visual Studio 进行调试时,它运行良好,没有任何脚本错误。 When I am hosting my application on IIS server, it shows console errors and my application styles are not working correctly.当我在 IIS 服务器上托管我的应用程序时,它显示控制台错误并且我的应用程序样式无法正常工作。 I have attached the error below.我附上了下面的错误。

Error : Resource interpreted as Stylesheet but transferred with MIME type text/javascript:错误:资源被解释为样式表,但使用 MIME 类型文本/javascript 传输:

Image:图片:

控制台错误信息

I had the exact same problem, cause by lines in my HTML in the following form:我遇到了完全相同的问题,由以下形式的 HTML 中的行引起:

<link rel="stylesheet" type="text/css" href="css/my_css_resource.css" />

The problem was fixed when I removed rel="stylesheet" from the tag.当我从标签中删除rel="stylesheet"时,问题得到了解决。

I can't comment due to low rep but this is very important.由于代表人数少,我无法发表评论,但这非常重要。

The answer that says:答案说:

"I had the exact same problem, cause by lines in my HTML in the following form: “我遇到了完全相同的问题,由以下形式的 HTML 中的行引起:

<link rel="stylesheet" type="text/css" href="css/my_css_resource.css" />

The problem was fixed when I removed rel="stylesheet" from the tag."当我从标签中删除 rel="stylesheet" 时,问题得到了解决。”

Is HORRIBLY wrong.是非常错误的。 rel="stylesheet" tells the browser this is a css file. rel="stylesheet" 告诉浏览器这是一个 css 文件。 Without it the browser doesn't know what to do with the CSS file, and any design code in it will NOT be executed.没有它,浏览器不知道如何处理 CSS 文件,并且其中的任何设计代码都不会被执行。

I have confirmed this by removing all occurrences of rel="stylesheet" from my html file: the result was a completely "naked" page, with absolutely no design whatsoever.我通过从我的 html 文件中删除所有出现的 rel="stylesheet" 来确认这一点:结果是一个完全“裸”的页面,绝对没有任何设计。 I have linked both bootstrap css and my own non-empty css, and tested it prior to removing rel="stylesheet" to see that style is actually modified by them.我已经链接了 bootstrap css 和我自己的非空 css,并在删除 rel="stylesheet" 之前对其进行了测试,以查看样式实际上是由它们修改的。

Mime types are set by the sender of the file, in this case a web server. Mime 类型由文件的发送者设置,在本例中为 Web 服务器。 The error message says that a file sent as plain text by the server, was interpreted as CSS by the browser.错误消息表示服务器以纯文本形式发送的文件被浏览器解释为 CSS。 In this case the problem is in the server, not in the browser.在这种情况下,问题出在服务器上,而不是在浏览器中。 The browser correctly interpreted this CSS file as a stylesheet.浏览器正确地将此 CSS 文件解释为样式表。 The server should have sent the right mime type.服务器应该发送了正确的 mime 类型。

Again, I am sorry I am posting this as an answer even though it is not, but I can't post comments because of low rep.再次,我很抱歉我将此作为答案发布,即使它不是,但由于代表较低,我无法发表评论。 If a moderator is reading this and want's to remove it, please either post it as a comment to the relevant answer or if possible mark the answer as wrong so people will not suffer because of it.如果版主正在阅读此内容并希望将其删除,请将其发布为相关答案的评论,或者如果可能,将答案标记为错误,以免人们因此而受苦。

I realized that with my new Windows 10 machine, I'd failed to enable Static Content in my local IIS.我意识到使用我的新 Windows 10 机器时,我无法在本地 IIS 中启用静态内容。 To do so, go to "Turn Windows Features On or Off" from your Control Panel, and navigate to the following location:为此,请从控制面板转到“打开或关闭 Windows 功能”,然后导航到以下位置:

在此处输入图片说明

Make sure this "Static Content" option is checked.确保选中此“静态内容”选项。 Then, bring up a command window as an administrator and perform an iisreset.然后,以管理员身份打开命令窗口并执行 iisreset。

Boom, fixed.轰,固定。

I had this same issue and it was due to using the wrong method to create the bundle.我遇到了同样的问题,这是由于使用错误的方法来创建包。 I carelessly copied a script bundle code and replaced it with CSS.我不小心复制了一个脚本包代码并用 CSS 替换了它。 Make sure you use Style Bundle for CSS and Script Bundle for JS.确保对 CSS 使用Style Bundle,对 JS 使用Script Bundle。 Same with when you render it.与渲染时相同。 Styles .Render() and Scripts .Render().样式.Render() 和脚本.Render()。

I had this:我有这个:

bundles.Add(new ScriptBundle("~/bundles/bootstrap-core-css").Include("~/Content/themes/bootstrap/css/bootstrap.min.css"));

I changed to:我改为:

bundles.Add(new StyleBundle("~/bundles/bootstrap-core-css").Include("~/Content/themes/bootstrap/css/bootstrap.min.css"));

I hope this helps.我希望这有帮助。

I had the same error right now, I found out that the css file didn't exists on the server, so, it was returning a 404 page.我现在遇到了同样的错误,我发现服务器上不存在 css 文件,因此,它返回了 404 页面。

So, you need to verify the link of the css.所以,你需要验证css的链接。

Resource interpreted as Stylesheet but transferred with MIME type text/javascript资源被解释为样式表但使用 MIME 类型 text/javascript 传输

The message above could be interpreted as:上面的消息可以解释为:

You requested for a css file, but we are sending back to you a javascript file.您请求了一个 css 文件,但我们正在向您发送一个 javascript 文件。

If you want to start debugging, I think you should start by ensuring the source of the file.如果你要开始调试,我认为你应该从确保文件的来源开始。

I hope this helps someone.我希望这可以帮助别人。

是的,我也看到了这个问题...这个问题是因为在 .htaccess 中你添加了 RewriteRule ...所以你必须更改 css 文件目录然后它会修复

I also faced this issue with CRA app.我也遇到了 CRA 应用程序的这个问题。 I just cleared my browser data and this seems to have fixed this issue.我刚刚清除了我的浏览器数据,这似乎解决了这个问题。 May be some cached files caused this.可能是某些缓存文件导致了这种情况。

Prior to clearing browser data, I check the same build on edge and firefox and it worked as expected.在清除浏览器数据之前,我在 edge 和 firefox 上检查了相同的构建并且它按预期工作。

Error: Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://abcxyz.com/static/css/2.0ce10a16.chunk.css".错误:资源被解释为样式表,但使用 MIME 类型 text/html 传输:“https://abcxyz.com/static/css/2.0ce10a16.chunk.css”。

Another possibility is if you have a lower case rewrite rule in your web.config file, similar to this:另一种可能性是,如果您的 web.config 文件中有一个小写的重写规则,类似于:

<rule name="LowerCaseRule1" stopProcessing="true">
    <match url="[A-Z]" ignoreCase="false" />
    <action type="Redirect" url="{ToLower:{URL}}" />
</rule>

If you include this type of rule, you need to ensure all of your script and stylesheet links are lower case.如果包含这种类型的规则,则需要确保所有脚本和样式表链接都是小写的。 If they aren't, you could see this warning.如果不是,您可能会看到此警告。

I have an Angular 6 project working with Docker and ran into this error.我有一个使用DockerAngular 6项目,但遇到了这个错误。 I have tried many sensible solutions here but none of them worked for me.我在这里尝试了许多明智的解决方案,但没有一个对我有用。 I have done research on this error in various ways.我以各种方式对此错误进行了研究。 Based on the answer here , I have added it to my nginx.conf file as follows.根据这里的答案,我已将其添加到我的nginx.conf文件中,如下所示。

My nginx.conf file has changed to the following:我的nginx.conf文件已更改为以下内容:

http
{
    # The line added.
    include /etc/nginx/mime.types;

    server {
        listen 80;
        listen [::]:80;
        server_name _;
        ...
    }
    ...
}

After this addition, my problem was resolved and the project worked successfully.添加后,我的问题解决了,项目成功运行。 I hope this answer will help those who are looking for an answer to the problem.我希望这个答案能帮助那些正在寻找问题答案的人。

I use react, get same error, I fixed by remove type="text/css" in the link tag, no error, and I verified that the css really get downloaded.我使用反应,得到同样的错误,我通过在链接标签中删除 type="text/css" 来修复,没有错误,我验证了 css 真的被下载了。

if you remove rel="stylesheet", no error, but css will NOT even download, so this is not a solution, it is a pitfall如果删除 rel="stylesheet",没有错误,但是 css 甚至不会下载,所以这不是解决方案,这是一个陷阱

        <link href="../src/css/gps/sidenav.css" rel="stylesheet" />  

暂无
暂无

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

相关问题 Flask:资源被解释为样式表,但使用 MIME 类型 text/html 传输 - Flask: Resource interpreted as Stylesheet but transferred with MIME type text/html 资源被解释为样式表,但在 AngularJS 中使用 MIME 类型 text/html 传输 - Resource interpreted as Stylesheet but transferred with MIME type text/html in AngularJS Firebase“资源解释为样式表,但使用 MIME 类型 text/html 传输” - Firebase "Resource interpreted as Stylesheet but transferred with MIME type text/html" Chrome说“资源解释为样式表,但使用MIME类型text / html传输” - Chrome says “Resource interpreted as Stylesheet but transferred with MIME type text/html” Meteor Resource解释为样式表,但使用MIME类型text / html进行传输 - Meteor Resource interpreted as Stylesheet but transferred with MIME type text/html 资源解释为样式表,但使用 MIME 类型 text/x-scss 传输 - Resource interpreted as Stylesheet but transferred with MIME type text/x-scss 资源被解释为样式表,但在 cloudflare 工作人员中使用 MIME 类型 text/html 传输 - Resource interpreted as Stylesheet but transferred with MIME type text/html in cloudflare workers 资源被解释为样式表,但与mime一起传输 - Resource interpreted as Stylesheet but transferred with mime 资源被解释为脚本,但以MIME类型text / html javascript传输 - Resource interpreted as Script but transferred with MIME type text/html javascript 资源解释为其他但使用MIME类型text / javascript传输? - Resource interpreted as other but transferred with MIME type text/javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM