Created
January 14, 2016 19:42
-
-
Save okeydoke/0b41702a5b24b68b7e66 to your computer and use it in GitHub Desktop.
Async css loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://stackoverflow.com/questions/5186638/how-to-asynchronously-load-css-using-jquery/32614409#32614409 | |
var stylesheet = document.createElement('link'); | |
stylesheet.href = '/inc/body/jquery/css/start/jquery-ui-1.8.10.custom.css'; | |
stylesheet.rel = 'stylesheet'; | |
stylesheet.type = 'text/css'; | |
// temporarily set media to something inapplicable to ensure it'll fetch without blocking render | |
stylesheet.media = 'only x'; | |
// set the media back when the stylesheet loads | |
stylesheet.onload = function() {stylesheet.media = 'all'} | |
document.getElementsByTagName('head')[0].appendChild(stylesheet); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment