Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function loadFontStyles() {
if (!window.localStorage) { return; }
var cssText;
if (cssText = localStorage.getItem('font-style-cache')) {
injectFontCSS(cssText);
} else {
fetch('/css/fonts.css').then(function(cssText) {
localStorage.setItem('font-style-cache', cssText);
return cssText;
}).then(injectFontCSS(cssText));
}
}
function injectFontCSS(cssText) {
var style = document.createElement('style');
style.type = 'text/css';
style.styleSheet.cssText = cssText;
document.head.appendChild(style);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.