Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function loadFont(t, e, n) {
return new Promise(resolve => {
const a = navigator.userAgent;
if (window.addEventListener && (!a.match(/(Android (2|3|4.0|4.1|4.2|4.3))|(Opera (Mini|Mobi))/) || a.match(/Chrome/))) {
let o = {};
try {
o = localStorage || {}
} catch (t) {}
const r = t, i = r + "url", s = r + "css", d = o[i], c = o[s], l = document.createElement("style");
if (l.rel = "stylesheet", document.head.appendChild(l), !c || d !== e && d !== n) {
const u = n && function () {
if (!window.FontFace) return !1;
const t = new FontFace("t", 'url("data:application/font-woff2,") format("woff2")', {});
return t.load(), "loading" === t.status
}() ? n : e, f = new XMLHttpRequest;
f.open("GET", u), f.onload = function () {
f.status >= 200 && f.status < 400 && (o[i] = u, o[s] = l.textContent = f.responseText)
resolve();
}, f.send()
} else {
l.textContent = c;
resolve();
}
}
});
}
loadFont('Affogato-1.0', '/assets/fonts/font-woff.css', '/assets/fonts/font-woff2.css').then(() => {
console.log('font loaded');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment