Last active
December 9, 2018 16:27
-
-
Save icodesido/5696948f3058b407aabab81ff364e202 to your computer and use it in GitHub Desktop.
Bundle all CSS fonts as Promises
This file contains hidden or 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 loadFonts() { | |
if ("fonts" in document) { | |
var font = new FontFace( | |
"Noto Serif", | |
"url(notoserif.woff2) format('woff2'), url(notoserif.woff) format('woff')" | |
); | |
var fontBold = new FontFace( | |
"Noto Serif", | |
"url(notoserif-bold.woff2) format('woff2'), url(notoserif-bold.woff) format('woff')", | |
{ weight: "700" } | |
); | |
Promise.all([ | |
font.load(), | |
fontBold.load() | |
]).then(function(loadedFonts) { | |
// Render them at the same time | |
loadedFonts.forEach(function(font) { | |
document.fonts.add(font); | |
}); | |
}); | |
} | |
} | |
if( navigator.connection && navigator.connection.saveData ) { | |
} else { | |
loadFonts(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment