如何使用跨域动态生成CSS
我正在尝试最小化并缓存服务器上的所有 CSS 文件。我有一个运行良好的脚本,但只能在本地运行,并且我们的 CSS 文件托管在 CDN 上。它是一个动态生成的 CSS 文件,其链接如下所示:
每个项目是由后面的 php 脚本加载的不同 css 文件最小化并适当缓存。这一切都很好,但我们的主站点无法使用它。 不起作用,因为它根本不加载。
我已将标头类型设置为:
header("Content-Type: text/css; charset: UTF-8");
header('Access-Control-Allow-Origin: *');
并且主站点不会加载它。我有什么想法可以解决这个问题吗?
I'm attempting to minimize and cache all of our CSS files on our server. I have a script that runs quite well but only works locally and our CSS files are hosted on a CDN. It's a dynamically generated CSS file and the link to it looks like this:
Each item is a different css file that gets loaded by the php script in the back minimized and cached as appropriate. That all works great but our main site can't use it. <link href="http://mysite/link" />
doesn't work as it doesn't load at all.
I've set header types as:
header("Content-Type: text/css; charset: UTF-8");
header('Access-Control-Allow-Origin: *');
And nothing the main site won't load it. Any ideas how I can fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用:
来包含样式表。
是包含样式的无效方法。另请参阅:MDN:
You should use:
to include style sheets.
<link rel="http://url">
is an invalid method to include styles. See also: MDN:<link>