Chrome 关于静态资源 (css/gif/png/js) 的警告
当加载网页时,我会在调试器中收到警告:
资源被解释为样式表,但是 使用 MIME 类型 text/plain 传输。
当浏览器请求 js、css、gif 和 png 文件时,我收到上述警告。
知道如何解决此警告
When ever the web page is loaded i am getting warning in the debugger as
Resource interpreted as stylesheet but
transferred with MIME type text/plain.
I am getting the above warning when the browser requests for js, css, gif and png files.
Any idea how to resolve this warning
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
嗯,错误消息说明了一切。
您的网络服务器发送错误/丢失 Content-Type HTTP 标头。
使用 HTTP 标头检查 并输入 js/css/gif/png 的 url并检查服务器发送的 Content-Type 标头(我猜根本没有或文本/纯文本)。
然后修复您的服务器以发送正确的 MIME 类型或联系您的服务器管理员。
正确的 Content-Type 值应该是
text/css
->对于 .css 文件image/gif
->对于 .gif 文件image/jpeg
->对于 .jpg/.jpeg 文件application/javascript
->对于 .js 文件image/png
->对于 .png 文件认为自己很幸运;)。现在它只是 Chrome 中的一个警告,在 Chrome 的早期版本中,当设置/发送了错误/丢失的 Content-Type 标头时,例如 CSS 根本没有应用。
Well the error message says it all.
Your webserver sends a wrong/missing Content-Type HTTP Header.
Use HTTP Header Check and enter the url of your js/css/gif/png and check what Content-Type header the server sends (I guess none at all or text/plain).
Then fix your server to send the correct mime type along or contact your server administrator.
The correct Content-Type values should be
text/css
-> for .css filesimage/gif
-> for .gif filesimage/jpeg
-> for .jpg/.jpeg filesapplication/javascript
-> for .js filesimage/png
-> for .png filesConsider yourself lucky ;). Now it is just a warning in Chrome, in earlier versions of Chrome when a wrong/missing Content-Type Header was set/sent the e.g. CSS wasn't applied at all.
我发现 Django 的开发网络服务器提供所有带有错误标头的图像/css 等。虽然 Jitter 的响应仍然是解决此问题的最佳方法,但修复服务器并不总是一种选择。
我发现您可以隐藏 Chrome 中的警告,并且如果您按住 Ctrl 键并单击 Chrome Inspect >> 中的两个标题(错误和日志),则只能查看错误和日志。控制台窗口;本质上隐藏了所有警告。
一个简单的技巧,但确实可以让 Django 中的调试变得不那么冗长和烦人。
I found that Django's development webserver serves all the images/css etc with incorrect headers as well. While Jitter's response is still the best approach to solving this, fixing the server is not always an option.
I found you can just hide the warnings in Chrome and only view the ERRORS and LOGS if you ctrl + click the two headers (ERRORS & LOGS) in the Chrome Inspect >> Console window; essentially hiding all warnings.
A simple hack, but sure makes debugging in Django less wordy and annoying.
是你的服务器配置有问题。您可能有一些正在使用 MIME 类型的杂散 .htaccess 文件。
It's a problem with your server configuration. You probably have some stray .htaccess files that are playing with the MIME types.
我也遇到了这些问题,当我对出现此错误的资源使用 HTTP 标头检查实用程序时,会返回一个有效的 Content-Type 标头,其中包含所请求资源的正确 mime 类型。我还使用 Firefox/Live HTTP 标头以及 wget 验证了这些标头。
我想知道这是否实际上是 Chrome 中的一个错误,导致它忽略这些类型文件的特定标头。
I'm also running into these issues and when I use the HTTP Header Check utility for the the resources that are getting this error, a valid Content-Type header is returned with the correct mime-type for the resource requested. I also validated these headers with Firefox/Live HTTP headers, as well as wget.
I'm wondering if this is actually a bug in Chrome that is causing it to ignore this particular header for these types of files.
重命名 /public/ 文件夹中的目录后,我遇到了这个问题。 Chrome 的缓存试图从旧目录加载文件,该目录现在返回错误页面而不是图像 - 因此错误表明它需要 .jpg 但收到 text/html
I had this problem after renaming a directory in my /public/ folder. Chrome's cache was trying to load the file from the old directory, which was now returning an error page instead of the image -- and thus the error stating that it was expecting a .jpg but receiving a text/html
你可以隐藏警告,购买添加这个cose到你的JS:
You can hide the warning, buy adding this cose to you JS: