Skip to content

Instantly share code, notes, and snippets.

@shelldandy
Last active April 27, 2018 15:25
Show Gist options
  • Save shelldandy/9119f9803b2a61cfb7cc366ee3836b2d to your computer and use it in GitHub Desktop.
Save shelldandy/9119f9803b2a61cfb7cc366ee3836b2d to your computer and use it in GitHub Desktop.
Master Race Typekit Solution by Glen Maddern
<head>
<script>
if (window.localStorage && window.localStorage._tk_cache) {
document.documentElement.classList.add('wf-active');
var script = document.createElement('script');
script.innerHTML = localStorage._tk_cache + ";(function () {var timeout = setTimeout(function () {document.documentElement.classList.remove('wf-active');}, 300); Typekit.load({ async: false, active: function () { clearTimeout(timeout); }});})();";
document.head.appendChild(script);
}
window._tk_onload = function () {
var req = new XMLHttpRequest()
req.addEventListener("load", function () {
window.localStorage._tk_cache = this.responseText;
});
req.open("GET", "https://use.typekit.net/XXXXXXXXXXXXXXXX.js");
req.send();
};
</script>
<script async src="https://use.typekit.net/XXXXXXXXXXXXXXXX.js"
onload="try { Typekit.load({ async: true, loading: window._tk_onload }) } catch (e) {}"></script>
</head>
@shelldandy
Copy link
Author

That goes right before closing the HEAD element, replace the XXXX with your actual typekit code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment