Created
October 14, 2015 00:52
-
-
Save jahfer/7d835fe36d1ee54aebca to your computer and use it in GitHub Desktop.
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 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