Skip to content

Instantly share code, notes, and snippets.

@perifer
Created October 25, 2012 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perifer/3952349 to your computer and use it in GitHub Desktop.
Save perifer/3952349 to your computer and use it in GitHub Desktop.
Improved web font loader code to prevent FOUT
// Custom web font loader inspired by the TypeKit loader.
WebFontConfig = {
fontdeck: {
id: FONTDECK_ID
},
active: function() {
clearTimeout(this._timeout);
}
};
(function() {
var a = document.getElementsByTagName("html")[0];
a.className += " wf-loading";
WebFontConfig._timeout = setTimeout(function () {
a.className = a.className.replace(/(\s|^)wf-loading(\s|$)/g, ""), a.className += " wf-inactive"
}, 3000);
var wf = document.createElement('script');
wf.src = '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment