如何允许从其他域引用 CSS 个文件?

How do I allow CSS files to be referenced from other domains?

我建立了两个网站。第一,http://static.example.com/, is hosting static files. Another one, http://www.example.com/ 托管 Web 应用程序。

http://www.example.com/, I reference images from the static site such as http://static.example.com/logo.png 内图像正确显示时。但是,当我输入:

<link rel="stylesheet" type="text/css" href="http://static.example.com/demo.css" />

在该页面上,demo.css 中的样式未应用于该页面。

在 Chrome 的开发者工具中:

CSS 文件是否有某种跨源策略?

如果我用 Stack Overflow 使用的 http://cdn.sstatic.net/Sites/Whosebug/all.css 替换样式文件,样式将应用于页面。

备注:

似乎与 content-type 有关。

对于不起作用的 CSS 文件:

Content-Type:text/plain

对于有效的 CSS 文件:

Content-Type:text/css

MDN docs

中所述

Here are some examples of resources which may be embedded cross-origin:

  • CSS with <link rel="stylesheet" href="...">. Due to the relaxed syntax rules of CSS, cross-origin CSS requires a correct Content-Type header. Restrictions vary by browser: IE, Firefox, Chrome, Safari (scroll down to CVE-2010-0051) and Opera.

查看 Content-type headers 并确保它们是正确的。