Less.js 不适用于 CDN?

发布于 2025-01-01 04:16:35 字数 602 浏览 5 评论 0原文

<link rel="stylesheet/less" href="http://mycdn.s3.amazon.com/css/web/style.less">
<script src="http://mycdn.s3.amazon.com/css/less-1.1.5.min.js"></script>

当我将 .less 文件放入 CDN 时,它显示:

XMLHttpRequest 无法加载 http://mycdn.s3.amazonaws.com/media/css /bootstrap/lib/bootstrap.less。 不允许来源 http://mydomain.com 访问控制允许来源。

为什么?我该如何解决这个问题?我不想在服务器端编译 .css 文件。我想让他们留在客户端。

<link rel="stylesheet/less" href="http://mycdn.s3.amazon.com/css/web/style.less">
<script src="http://mycdn.s3.amazon.com/css/less-1.1.5.min.js"></script>

When I put my .less file in my CDN, it says:

XMLHttpRequest cannot load
http://mycdn.s3.amazonaws.com/media/css/bootstrap/lib/bootstrap.less.
Origin http://mydomain.com is not allowed by
Access-Control-Allow-Origin.

Why? How do I fix this? I do NOT want to compile .css files on server side. I want to keep them client side.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只涨不跌 2025-01-08 04:16:35

MDN 上这篇相当长的文章将帮助您了解正在发生的事情 - https://developer.mozilla.org/En /HTTP_access_control

基本上你已经遇到了跨域安全模型

如果你坚持不想在服务器上编译CSS,你可以尝试从你自己的子域提供它,即映射一个Amazon CDN 的子域,但我不确定这是否能解决您的问题。

我实际上想问为什么您不想编译 .CSS 服务器端,因为这将为您的访问者带来最佳性能,并使您能够轻松地将 CSS 托管在 CDN 上。

在 HTML 之后,CSS 是进入浏览器的下一个最重要的项目,因此它可以开始布局和渲染页面,通过将 JS 插入到混合中,您会减慢速度(特别是因为 JS 可以阻止某些应用程序中的并行下载)浏览器,并且会在执行时阻塞 UI 线程)

This rather long article from MDN will help you understand what's going on - https://developer.mozilla.org/En/HTTP_access_control

Basically you've run into the cross-domain security model

If you're adamant that you don't want to compile CSS on the server, you could try serving it from your own sub-domain i.e. map a sub-domain to the Amazon CDN but I'm not sure that will fix your problem.

I'd actually question why you don't want to compile the .CSS server-side as this will result in the best performance for your visitors and enables you to easily host the CSS on a CDN.

After the HTML, the CSS is the next most important item to get into the browser so it can start layout and render of a page, by inserting JS into the mix you're slowing this down (particulary as JS can block parallel downloads in some browsers, and will block the UI thread while it executes)

仅一夜美梦 2025-01-08 04:16:35

Amazon S3 现在支持跨源资源共享:
http://aws.typepad.com /aws/2012/08/amazon-s3-cross-origin-resource-sharing.html

按照说明操作并向您的存储桶添加 CORS 配置选项应该可以解决问题。

Amazon S3 now supports Cross Origin Resource Sharing:
http://aws.typepad.com/aws/2012/08/amazon-s3-cross-origin-resource-sharing.html

Follow the instructions and add a CORS Configuration option to your bucket should fix the problem.

彼岸花似海 2025-01-08 04:16:35

如果你想修复跨域访问,那么你需要查看诸如跨源资源共享(http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing)之类的东西,但这仅受现代浏览器或 JSONP 支持,但这我认为你的 CDN 是不可能的。

我必须同意@Andy Davies 的观点,为什么你不编译 .less 因为这可以解决问题?这是由于交付的文件大小所致,还是在实时推送文件时无法编译 .less ?在 Visual Studio 中,您可以使用 http://www.mindscapehq.com/products/web-workbench 等插件 将在发生更改时进行编译。

If you want to fix cross domain access then you need to look at things like Cross Origin Resource Sharing (http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing) but this is only supported by modern browsers, or JSONP but this would not be possible with your CDN I think.

I have to agree with @Andy Davies that why are you not compiling the .less since this would fix the issue? is this due to the file size being delivered or can you not compile .less as you push the files live? In Visual Studio you can use addins like http://www.mindscapehq.com/products/web-workbench which will compile when changes occur.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文