Skip to content

Instantly share code, notes, and snippets.

@itsmethemojo
Created May 17, 2016 07:05
Show Gist options
  • Save itsmethemojo/99efd3be13e93a291e958e656cbaf2e5 to your computer and use it in GitHub Desktop.
Save itsmethemojo/99efd3be13e93a291e958e656cbaf2e5 to your computer and use it in GitHub Desktop.
(function() {
  var raf = window.RequestAnimationFrame  ||
      window.mozRequestAnimationFrame ||
      window.webkitRequestAnimationFrame ||
      window.msRequestAnimationFrame;
  // defer loading of all app relevant javascript
  // and non criticial CSS
  function deferLoad() {
    // JS
    var element = document.createElement("script"),
      l = document.createElement('link');
    element.src = "javascript/app.js";
    document.body.appendChild(element);
    // CSS
    l.rel = 'stylesheet';
    l.href = 'css/main.css';
    document.getElementsByTagName('head')[0].appendChild(l);
  }
  if (raf) {
    raf(deferLoad);
  } else if (window.addEventListener) {
    window.addEventListener("load", deferLoad, false);
  } else if (window.attachEvent) {
    window.attachEvent("onload", deferLoad);
  } else {
    window.onload = deferLoad;
  }
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment