Skip to content

Instantly share code, notes, and snippets.

@derekjohnson
Last active December 28, 2015 18:49
Show Gist options
  • Save derekjohnson/7546008 to your computer and use it in GitHub Desktop.
Save derekjohnson/7546008 to your computer and use it in GitHub Desktop.
Font loader
(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