I need to load a bunch of CSS files through ajax and call the animation when the stylesheet has finished loading, otherwise the animation will fail.
What I did and got used to work well until I switched to this cross-domain is:
$.get(resource.url, {cache:true}, function(css) {
$("head").append($("<link>",{
rel: "stylesheet",
type: "text/css",
href: resource.url
}));
}).then(function(){
});
This works fine while resource.urlin the same domain. As soon as I try to load css from another domain $.get, the following will happen:
XMLHttpRequest cannot load https://example.com/style.css. Origin https://example.com is not allowed by Access-Control-Allow-Origin.
So, I tried adding CORS to the header via .htaccess:
<IfModule mod_headers.c>
<FilesMatch "\.(css|js)$">
Header add Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
This adds the CORS header to all CSS and JS resources.
For some reason, CORS doesn't seem to affect either chrome or firefox (latest versions).
, $.getScript js , $.get:
$.get("https://example.com/script.js", {cache: false}, $.noop, "script");
$.get("https://example.com/script.js", {cache: false}, $.noop);
, CORS , -, $.getScript, CSS.
.
? ...