Last active
December 28, 2015 18:49
-
-
Save derekjohnson/7546008 to your computer and use it in GitHub Desktop.
Font loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(win, doc, undefined) { | |
// sanity check - is it a decent browser | |
if('addEventListener' in win && 'localStorage' in win && 'querySelector' in doc) { | |
// https://gist.github.com/scottjehl/5406853 | |
var injectref = doc.getElementsByTagName('script')[0], | |
loadCSS = function(href) { | |
var fontslink = doc.createElement('link'); | |
fontslink.rel = 'stylesheet'; | |
fontslink.href = href; | |
if(injectref && injectref.parentNode) { | |
injectref.parentNode.insertBefore(fontslink, injectref); | |
} | |
}; | |
// Use the Network Information API where it's available | |
if(win.navigator.connection) { | |
var connection = win.navigator.connection, | |
slow = connection.type === 3 || connection.type === 4 || connection.bandwidth <= 0.25; | |
} | |
if(!slow) { | |
loadCSS('css/fonts.css'); | |
} | |
} // eof sanity check | |
})(this, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment