Skip to content

Instantly share code, notes, and snippets.

@siffring
Created October 30, 2013 19:25
Show Gist options
  • Save siffring/7238625 to your computer and use it in GitHub Desktop.
Save siffring/7238625 to your computer and use it in GitHub Desktop.
An asynchronous loader for TypeKit
<script>
(function() {
var config = {
kitId: '[your typekit kit id goes here]',
scriptTimeout: 3000
};
var h=document.getElementsByTagName("html")[0];h.className+=" wf-loading";var t=setTimeout(function(){h.className=h.className.replace(/(\s|^)wf-loading(\s|$)/g," ");h.className+=" wf-inactive"},config.scriptTimeout);var tk=document.createElement("script"),d=false;tk.src='//use.typekit.net/'+config.kitId+'.js';tk.type="text/javascript";tk.async="true";tk.onload=tk.onreadystatechange=function(){var a=this.readyState;if(d||a&&a!="complete"&&a!="loaded")return;d=true;clearTimeout(t);try{Typekit.load(config)}catch(b){}};var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(tk,s)
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment