Skip to content

Instantly share code, notes, and snippets.

@englishextra
Last active April 3, 2016 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save englishextra/5b838277a698c36502309d19c4839eed to your computer and use it in GitHub Desktop.
Save englishextra/5b838277a698c36502309d19c4839eed to your computer and use it in GitHub Desktop.
/*!
* load JS with requestAnimationFrame
* stackoverflow.com/questions/28394097/async-loading-css-stylesheet-using-requestanimationframe
*/
function loadJSwithRaf(s, c) {
function l() {
var a = document.getElementsByTagName("script")[0],
t = document.createElement("script");
t.src = s;
t.async = !0;
t.charset = "utf-8";
a.parentNode.insertBefore(t, a);
c && "function" === typeof c && (t.onload = c);
return t;
}
"function" === typeof requestAnimationFrame ? requestAnimationFrame(l) : "function" === typeof mozRequestAnimationFrame ? mozRequestAnimationFrame(l) : "function" === typeof webkitRequestAnimationFrame ? webkitRequestAnimationFrame(l) : "function" === typeof msRequestAnimationFrame ? msRequestAnimationFrame(l) : "function" === typeof window.addEventListener ? window.addEventListener("load", l) : window.onload = l;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment