Skip to content

Instantly share code, notes, and snippets.

@icodesido
Last active December 9, 2018 16:27
Show Gist options
  • Save icodesido/5696948f3058b407aabab81ff364e202 to your computer and use it in GitHub Desktop.
Save icodesido/5696948f3058b407aabab81ff364e202 to your computer and use it in GitHub Desktop.
Bundle all CSS fonts as Promises
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