2014-03-06 45 views
2

我获得两个控制台的警告在Chrome:脚本被解释为样式表,但使用MIME类型text/html转

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> 
<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文件内,所以我在b加入header('Content-type: text/css');例如页面脚本。我还在.htaccess文件中包含了AddCharset utf-8 .css .jsAddType text/css .css,但没有运气放松警告。

究竟是什么导致了这一点,你如何摆脱警告?

+1

你有相对包括在你的base.css? – avarx

+0

@ava,是的,我在样式表中有相对包含,base.css也只是'@ import'其余的样式表。 – Laniakea

+0

试试绝对路径。只是为了确定它是这个问题。 – avarx

回答

1

好的,我发现了这个问题。

我得到警告的原因是因为我在base.css中使用@import来引入不在它们位置的脚本。准确地说,我错过了2个脚本,所以推测这就是我得到2个警告的原因。

1

需要注意的是:

实质上,当每个请求包括 那些用于静态内容的请求都被验证时,也可能导致问题。

在我的情况下,我的应用程序是弹簧启动应用程序。所以我只是在我的安全配置文件中添加了排除项目,以查看有关文件的路径...

注 - 此解决方案基于SpringBoot ...你可能需要做的可能会有所不同根据您所使用的编程语言和/或你正在使用什么框架

所以我们说一些路径,以我的静态内容进行了哪些导致的错误如下:

称为路径 “插件”

http://localhost:8080/plugins/styles/css/file-1.css

http://localhost:8080/plugins/styles/css/file-2.css

http://localhost:8080/plugins/js/script-file.js

和称为路径 “页面”

http://localhost:8080/pages/styles/css/style-1.css

http://localhost:8080/pages/styles/css/style-2.css

http://localhost:8080/pages/js/scripts.js

然后我刚才添加的排除在我的春节,启动安全配置如下:

@Configuration 
@EnableGlobalMethodSecurity(prePostEnabled = true) 
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.authorizeRequests() 
      .antMatchers(<comma separated list of other permitted paths>, "/plugins/**", "/pages/**").permitAll() 
      // other antMatchers can follow here 
    } 

} 


扣除这些路径"/plugins/**""/pages/**"从认证所犯的错误消失。


干杯!

相关问题