Skip to content

Instantly share code, notes, and snippets.

@jahfer
Created October 14, 2015 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahfer/7d835fe36d1ee54aebca to your computer and use it in GitHub Desktop.
Save jahfer/7d835fe36d1ee54aebca to your computer and use it in GitHub Desktop.
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