Last active
May 3, 2019 11:14
-
-
Save chriswinch/3d8b05ae9c190781a3b7608211500b28 to your computer and use it in GitHub Desktop.
Google Web Font Loader with LocalStorage
This file contains 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
<script> | |
if (window.localStorage && window.localStorage._gf_cache) { | |
document.documentElement.classList.add('wf-active'); | |
var script = document.createElement('script'); | |
script.innerHTML = localStorage._gf_cache; | |
document.head.appendChild(script); | |
} | |
window._gfonload = function () { | |
var req = new XMLHttpRequest() | |
req.addEventListener("load", function () { | |
window.localStorage._gf_cache = this.responseText; | |
}); | |
req.open("GET", "https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"); | |
req.send(); | |
}; | |
WebFontConfig = { | |
google: { | |
families: ['Droid Sans'] | |
}, | |
loading: window._gfonload | |
} | |
</script> | |
<script async src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment