Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to conditionally load Google Font client-side while avoiding FOUT
* This function used with gratitude from
* I want to refactor this to ES6 so badly but
* since it has to reside in the DOM to avoid FOUT,
* we can't transpile with Babel unfortunately
function addCss(fileName) {
var head = document.head
, link = document.createElement('link')
link.type = 'text/css'
link.rel = 'stylesheet'
link.href = fileName
// Wrap this call with any sort of conditional you like
h1 {
font-family: 'Open Sans';
<h1>Hello World</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment