admin管理员组

文章数量:1287524

<link rel="stylesheet/less" href=".less">
<script src=".1.5.min.js"></script>

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

XMLHttpRequest cannot load .less. Origin is not allowed by Access-Control-Allow-Origin.

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

<link rel="stylesheet/less" href="http://mycdn.s3.amazon./css/web/style.less">
<script src="http://mycdn.s3.amazon./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./media/css/bootstrap/lib/bootstrap.less. Origin http://mydomain. is not allowed by Access-Control-Allow-Origin.

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

Share Improve this question edited Feb 21, 2012 at 20:36 PeeHaa 72.7k60 gold badges194 silver badges264 bronze badges asked Jan 30, 2012 at 8:39 TIMEXTIMEX 272k367 gold badges801 silver badges1.1k bronze badges 2
  • Possible duplicate stackoverflow./questions/8176913/… – Amar Palsapure Commented Jan 30, 2012 at 8:44
  • 1 On a note for anyone else ending up here: I've gotten the same error on my web host's web server. It was erroneously sending empty responses because the .less file/mime type was unknown. Configuring the web server to properly serve .less files fixed it. (It was not a cross-domain request, all .js/.less files were served from the same folder.) – Joel Purra Commented Jun 24, 2012 at 19:44
Add a ment  | 

3 Answers 3

Reset to default 5

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

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

If you're adamant that you don't want to pile 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 pile 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)

Amazon S3 now supports Cross Origin Resource Sharing: http://aws.typepad./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.

If you want to fix cross domain access then you need to look at things like Cross Origin Resource Sharing (http://en.wikipedia/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 piling the .less since this would fix the issue? is this due to the file size being delivered or can you not pile .less as you push the files live? In Visual Studio you can use addins like http://www.mindscapehq./products/web-workbench which will pile when changes occur.

本文标签: javascriptLessjs does not work with CDNsStack Overflow