Skip to content

Instantly share code, notes, and snippets.

@lastguest
Created October 8, 2015 10:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lastguest/76eb6e307ea7d3fbe37c to your computer and use it in GitHub Desktop.
Save lastguest/76eb6e307ea7d3fbe37c to your computer and use it in GitHub Desktop.
[JavaScript] asyncLoadCSS
function asyncLoadCSS (css_href) {
var css_link = function () {
var h = document.getElementsByTagName('head')[0]
var l = document.createElement('link')
l.rel = 'stylesheet'
l.href = css_href
h.parentNode.insertBefore(l, h)
}, RAF = requestAnimationFrame || mozRequestAnimationFrame
|| webkitRequestAnimationFrame || msRequestAnimationFrame
if (RAF) RAF(css_link); else window.addEventListener('load', css_link)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment