@ahren is almost fixable. However, using the callback when the css file is completed, loading via dynamic href change on the link element does NOT work on most mobile devices.
Instead, try directly inserting the style into the style element using load .. ultimately supported by most modern browsers, including mobile.
UPDATED enable IE 8- support; NOTE. This requires that you introduce a dummy rule in your css to check the css load (in this case, use body {ready: true;})
css
body {ready:true;} ...
HTML
<style id="your-style-element"></style>
Javascript
if (document.createStyleSheet) { //Wait for style to be loaded var wait = setInterval(function(){ //Check for the style to be applied to the body if($('body').css('ready') === 'true') { clearInterval(wait); //CSS ready } }, 300); document.createStyleSheet(url); } else { //Dynamically load the css for this doc $("#your-style-element").load(url,function(){ //CSS ready }); }
Chad brown
source share