Skip to content

Instantly share code, notes, and snippets.

@chriswinch
Last active May 3, 2019 11:14
Show Gist options
  • Save chriswinch/3d8b05ae9c190781a3b7608211500b28 to your computer and use it in GitHub Desktop.
Save chriswinch/3d8b05ae9c190781a3b7608211500b28 to your computer and use it in GitHub Desktop.
Google Web Font Loader with LocalStorage
<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