Skip to content

Instantly share code, notes, and snippets.

@itamar
Created June 22, 2016 10:04
Show Gist options
  • Select an option

  • Save itamar/71e16c5c0c9b8081dfc62bd80ea5b4ac to your computer and use it in GitHub Desktop.

Select an option

Save itamar/71e16c5c0c9b8081dfc62bd80ea5b4ac to your computer and use it in GitHub Desktop.
LoadCSS.js
// http://www.gotknowhow.com/articles/how-to-asynchronously-load-font-awesome-css-file
<script>
// Asynchronously load non-critical css
function loadCSS(e, t, n) { "use strict"; var i = window.document.createElement("link"); var o = t || window.document.getElementsByTagName("script")[0]; i.rel = "stylesheet"; i.href = e; i.media = "only x"; o.parentNode.insertBefore(i, o); setTimeout(function () { i.media = n || "all" }) }
// load css file async
loadCSS("//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css");
</script>
// load css file async
loadCSS("/css/my-test.css");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment