我在 Chrome 中收到两个控制台警告:
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://domain/". domain/:11
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://domain/". domain/:11
在第 11 行,我有:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
这是 head 部分的所有代码:
<head>
<meta charset="UTF-8">
<title>Laoautod</title>
<meta http-equiv = "Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/base.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="js/center.js"></script>
<script type="text/javascript">
function displayResult()
{
var x=document.getElementById("checkbox").defaultChecked;
alert(x);
}
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'accountID']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
HTML 代码位于 index.php 文件内,因此我在页面脚本的开头添加了 header('Content-type: text/css');
。我还在 .htaccess
文件中添加了 AddCharset utf-8 .css .js
和 AddType text/css .css
,但没有丢失警告.
到底是什么原因造成的?如何消除这些警告?
最佳答案
好的,我发现问题了。
我收到警告的原因是因为我在 base.css 中使用 @import
引入不在其位置的脚本。准确地说,我缺少 2 个脚本,所以大概这就是我收到 2 个警告的原因。
关于javascript - 脚本被解释为样式表,但以 MIME 类型 text/html 传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22221147/