资源解释为脚本,但使用MIME类型text/x-c ++进行传输

fxp*_*fxp 6 css less

没有初学者.

在下面写了一个测试html

<head>
    <link rel="stylesheet" type="text/css" href="404.less">
    <script src="http://lesscss.googlecode.com/files/less-1.3.0.min.js" type="text/javascript"></script>
</head>
<body>test</body>
Run Code Online (Sandbox Code Playgroud)

但在Chrome中收到了警告

资源解释为脚本,但使用MIME类型text/x-c ++传输:"http://lesscss.googlecode.com/files/less-1.3.0.min.js".

为什么?

Ala*_*lan 10

您可能希望链接标记说:

<link rel="stylesheet/less" type="text/css" href="404.less">
Run Code Online (Sandbox Code Playgroud)

也就是说,如果这是从网络服务器提供的,则可能是从文件扩展名中检测到错误的mime类型.如果它是一个apache服务器,那么有一个简单的解决方案.将此添加到/创建webroot中的.htaccess文件,其中包含以下行:

AddType text/css less 
Run Code Online (Sandbox Code Playgroud)